将数组编码为一行

时间:2018-06-26 12:24:44

标签: javascript php arrays json

我有这段编码数组的代码,并将其附加到JSON文件中:

  $current_data = file_get_contents('d.json');
  $array_data = json_decode($current_data, true);
  $form_data = array('cot' => 'ua','id' => $post_id,'name' => $user_name,'tweet_url' => $tweet_url,'post_date' => $post_date,'post_text' => $post_text,'avatar' => $user_profile_img,'post_device' => $post_device,'location' => $user_location,'user_followers_count' => $user_followers_count,'user_created_at' => $user_created_at,'user_screen_name' => $user_screen_name,);
  $array_data[$post_id] = $form_data;
  $data_proccesed = json_encode($array_data, JSON_PRETTY_PRINT);
  file_put_contents('d.json', $data_proccesed);

附上以下内容:

{
"1011151247779348480": {
    "id": "1011151247779348480",
    "name": "infires",
    "tweet_url": "https:\/\/twitter.com\/yeonkimin_09\/status\/1011151247779348480",
    "post_date": "Mon Jun 25 07:36:58 +0000 2018",
    "post_text": "RT @savantyoongi: they may be the family of savageness but yoongi\u2019s family love him so much. whether he\u2019s famous or not, they love him with\u2026",
    "avatar": "https:\/\/pbs.twimg.com\/profile_images\/1005757319647354881\/ltnID8te_normal.jpg",
    "post_device": "<a href=\"http:\/\/twitter.com\/download\/android\" rel=\"nofollow\">Twitter for Android<\/a>",
    "location": "",
    "user_followers_count": 9,
    "user_created_at": "Mon Jan 08 07:38:37 +0000 2018",
    "user_screen_name": "yeonkimin_09"
},
}

我想像这样在一行中添加它:

{"1011151247779348480": {"id": "1011151247779348480","name":"infires","tweet_url": "https:\/\/twitter.com\/yeonkimin_09\/status\/1011151247779348480","post_date": "Mon Jun 25 07:36:58 +0000 2018","post_text": "RT @savantyoongi: they may be the family of savageness but yoongi\u2019s family love him so much. whether he\u2019s famous or not, they love him with\u2026","avatar": "https:\/\/pbs.twimg.com\/profile_images\/1005757319647354881\/ltnID8te_normal.jpg","post_device": "<a href=\"http:\/\/twitter.com\/download\/android\" rel=\"nofollow\">Twitter for Android<\/a>","location": "","user_followers_count": 9,"user_created_at": "Mon Jan 08 07:38:37 +0000 2018","user_screen_name": "yeonkimin_09"},}

有什么想法吗?

0 个答案:

没有答案