2017-10-24 14 views
1

私はDJSエンコードされたデータを持っていますが、これはaws dynamoDBにアップロードする必要があります。
私はこれに続きましたlink1 & link2リンク。私のデータはDBにアップロードされていません。
は私が私のJSONを共有しましょう、私はdynamo.Canに新しいです
誰も私を助けて..AWS DynamoDBにJsonエンコードデータを追加します

Json.phpは

header('Content-Type: application/json'); 

$feed_url = 'http://localhost/json/j_xml.xml'; 
$xml_data = simplexml_load_file($feed_url); 

// -------------------------------------------------------------------- 

$i=0; 
$response = array('return' => true,'message' => 'success','details' => array()); 
foreach($xml_data->channel->item as $ritem) { 
$e_wp       = $ritem->children("wp", true); 
$e_author      = $ritem->children("dc", true); 
$e_content      = $ritem->children("content", true); 
// -------------------------------------- 
if((string)$e_wp->status =='publish') { 
$post_id      = (string)$ritem->guid; 
$post_id      = explode('=', $post_id); 
$content['article_post_id']  = $post_id[1]; 
$content['article_title']  = (string)$ritem->title; 
$content['article_cat_slug'] = 'News'.$post_id[1]; 
$content['article_mob_title'] = (string)$ritem->title; 
$content['article_category'] = (string)$ritem->category; 
$content['article_pub_date'] = (string)$e_wp->post_date; 
$content['article_description'] = (string)$ritem->description; 
$content['article_content']  = (string)$e_content->encoded; 
$content['article_author']  = (string)$e_author->creator; 
$content['article_seo_desc'] = ''; 
$content['article_seo_tags'] = ''; 
$content['article_fb_title'] = ''; 
$content['article_fb_desc']  = ''; 
$content['article_twitter']  = ''; 
$content['article_create_date'] = (string)$e_wp->post_date_gmt; 
$content['article_status']  = (string)$e_wp->status; 
} 
array_push($response['details'],$content); 
} 
echo json_encode($response,JSON_PRETTY_PRINT); 

答えて

0

私は解決策を考え出しました。
これは将来的にこれを助けるかもしれないと思います。
私はマーシャラーの方法に従った。

require('aws/aws-autoloader.php'); 
use Aws\DynamoDb\DynamoDbClient; 
use Aws\DynamoDb\Marshaler; 

// -------------------------------------------------------------------- 

$feed_url = 'http://localhost/json/j_xml.xml'; 
$xml_data = simplexml_load_file($feed_url); 

// -------------------------------------------------------------------- 

$i=0; 
$results = array('return' => true,'message' => 'success','details' => array(),'response'=>array()); 
$AWS_ACCESS_KEY_ID = '******************'; 
$AWS_SECRET_ACCESS_KEY = '*******************'; 
$AWS_REGION = '<region-code>'; 

$client = DynamoDbClient::factory(array(
      'version'  => '2012-08-10', 
      'credentials' => array(
      'key' => $AWS_ACCESS_KEY_ID, 
      'secret' => $AWS_SECRET_ACCESS_KEY, 
      ), 
      'region' => $AWS_REGION 
      )); 

$marshaler = new Marshaler(); 
foreach($xml_data->channel->item as $ritem) { 
$e_wp       = $ritem->children("wp", true); 
$e_author      = $ritem->children("dc", true); 
$e_content      = $ritem->children("content", true); 
// -------------------------------------- 
if((string)$e_wp->status =='publish') { 
$post_id      = (string)$ritem->guid; 
$post_id      = explode('=', $post_id); 
$content['ArticleID']   = $post_id[1]; 
$content['article_title']  = (string)$ritem->title; 
$content['article_cat_slug'] = 'News'.$post_id[1]; 
$content['article_mob_title'] = (string)$ritem->title; 
$content['article_category'] = (string)$ritem->category; 
$content['article_pub_date'] = (string)$e_wp->post_date; 
$content['article_description'] = (string)$ritem->description; 
$content['article_content']  = (string)$e_content->encoded; 
$content['article_author']  = (string)$e_author->creator; 
/* DynamoDB doesnot accept empty string 
$content['article_seo_desc'] = ''; 
$content['article_seo_tags'] = ''; 
$content['article_fb_title'] = ''; 
$content['article_fb_desc']  = ''; 
$content['article_twitter']  = ''; 
*/ 
$content['article_create_date'] = (string)$e_wp->post_date_gmt; 
$content['article_status']  = (string)$e_wp->status; 
$content = array_filter($content); 
$json = json_encode($content,JSON_PRETTY_PRINT); 
$response = $client->putItem([ 
    'TableName' => 'Article', 
    'Item'  => $marshaler->marshalJson($json) 
]); 

} 
array_push($results['details'],$content); 
array_push($results['response'],$response); 

}