我目前在显示特定类型的所有数组值时遇到问题我正在尝试从json中获取所有消息
这是我的代码:
<?php
$request = 'https://devblogs.instavoice.com';
$response = file_get_contents($request);
$jsonobj = json_decode($response,true);
echo $jsonobj->status;
echo $jsonobj[0]->msg_content;
?>
这是我想要获取的json:
{"cmd":"fetch_vobolos","status":"ok","no_more_record":true,"blog_msgs":[{"from_blogger_id":17198634,"msg_id":19046254,"msg_content_type":"t","msg_content":"dsd\u0027.$msg.\u0027","duration":11,"msg_dt":1471675984000,"annotation":"","blogger_display_name":"48669341","pic_uri":"http://devblogs.instavoice.com/vobolo/static-contents/images/default_profile_pic.jpg","profile_picture_thumbnail_URI":"http://devblogs.instavoice.com/vobolo/static-contents/images/default_profile_pic_thumbnail.jpg","profileFolderName":"8488/","blogFolderName":"8488/","is_msg_base64":false,"msg_flow":"s","isReceivedMsg":false,"type":"vb","like_cnt":0,"comment_cnt":0,"shares_cnt":0,"is_self_liked":false,"is_self_commented":false,"is_self_shared":false,"is_shared":false,"linked_blog_id":0,"by_profile_picture_URI":"http://devblogs.instavoice.com/vobolo/static-contents/images/default_profile_pic.jpg","by_profile_picture_thumbnail_URI":"http://devblogs.instavoice.com/vobolo/static-contents/images/default_profile_pic_thumbnail.jpg","source_app_type":"","is_tagged":false},{"from_blogger_id":17198634,"msg_id":19046253,"msg_content_type":"t","msg_content":"rasdhulsdsa","duration":11,"msg_dt":1471675507000,"annotation":"","blogger_display_name":"48669341","pic_uri":"http://devblogs.instavoice.com/vobolo/static-contents/images/default_profile_pic.jpg","profile_picture_thumbnail_URI":"http://devblogs.instavoice.com/vobolo/static-contents/images/default_profile_pic_thumbnail.jpg","profileFolderName":"8488/","blogFolderName":"8488/","is_msg_base64":false,"msg_flow":"s","isReceivedMsg":false,"type":"vb","like_cnt":0,"comment_cnt":0,"shares_cnt":0,"is_self_liked":false,"is_self_commented":false,"is_self_shared":false,"is_shared":false,"linked_blog_id":0,"by_profile_picture_URI":"http://devblogs.instavoice.com/vobolo/static-contents/images/default_profile_pic.jpg","by_profile_picture_thumbnail_URI":"http://devblogs.instavoice.com/vobolo/static-contents/images/default_profile_pic_thumbnail.jpg","source_app_type":"","is_tagged":false},{"from_blogger_id":17198634,"msg_id":19046252,"msg_content_type":"t","msg_content":"rasdhulsdsa","duration":11,"msg_dt":1471675294000,"annotation":"","blogger_display_name":"48669341","pic_uri":"http://devblogs.instavoice.com/vobolo/static-contents/images/default_profile_pic.jpg","profile_picture_thumbnail_URI":"http://devblogs.instavoice.com/vobolo/static-contents/images/default_profile_pic_thumbnail.jpg","profileFolderName":"8488/","blogFolderName":"8488/","is_msg_base64":false,"msg_flow":"s","isReceivedMsg":false,"type":"vb","like_cnt":0,"comment_cnt":0,"shares_cnt":0,"is_self_liked":false,"is_self_commented":false,"is_self_shared":false,"is_shared":false,"linked_blog_id":0,"by_profile_picture_URI":"http://devblogs.instavoice.com/vobolo/static-contents/images/default_profile_pic.jpg","by_profile_picture_thumbnail_URI":"http://devblogs.instavoice.com/vobolo/static-contents/images/default_profile_pic_thumbnail.jpg","source_app_type":"","is_tagged":false},{"from_blogger_id":17198634,"msg_id":19046243,"msg_content_type":"t","msg_content":"ddsssd","duration":6,"msg_dt":1471670493000,"annotation":"","blogger_display_name":"48669341","pic_uri":"http://devblogs.instavoice.com/vobolo/static-contents/images/default_profile_pic.jpg","profile_picture_thumbnail_URI":"http://devblogs.instavoice.com/vobolo/static-contents/images/default_profile_pic_thumbnail.jpg","profileFolderName":"8488/","blogFolderName":"8488/","is_msg_base64":false,"msg_flow":"s","isReceivedMsg":false,"type":"vb","like_cnt":0,"comment_cnt":0,"shares_cnt":0,"is_self_liked":false,"is_self_commented":false,"is_self_shared":false,"is_shared":false,"linked_blog_id":0,"by_profile_picture_URI":"http://devblogs.instavoice.com/vobolo/static-contents/images/default_profile_pic.jpg","by_profile_picture_thumbnail_URI":"http://devblogs.instavoice.com/vobolo/static-contents/images/default_profile_pic_thumbnail.jpg","source_app_type":"","is_tagged":false},{"from_blogger_id":17198634,"msg_id":19046242,"msg_content_type":"t","msg_content":"asdsdas","duration":7,"msg_dt":1471670413000,"annotation":"","blogger_display_name":"48669341","pic_uri":"http://devblogs.instavoice.com/vobolo/static-contents/images/default_profile_pic.jpg","profile_picture_thumbnail_URI":"http://devblogs.instavoice.com/vobolo/static-contents/images/default_profile_pic_thumbnail.jpg","profileFolderName":"8488/","blogFolderName":"8488/","is_msg_base64":false,"msg_flow":"s","isReceivedMsg":false,"type":"vb","like_cnt":0,"comment_cnt":0,"shares_cnt":0,"is_self_liked":false,"is_self_commented":false,"is_self_shared":false,"is_shared":false,"linked_blog_id":0,"by_profile_picture_URI":"http://devblogs.instavoice.com/vobolo/static-contents/images/default_profile_pic.jpg","by_profile_picture_thumbnail_URI":"http://devblogs.instavoice.com/vobolo/static-contents/images/default_profile_pic_thumbnail.jpg","source_app_type":"","is_tagged":false}],"last_blog_id":19046254,"before_blog_id":19046242,"device_id":61758}
我在“msg_content”上显示所有消息时遇到困难,但它返回错误。
答案 0 :(得分:1)
要查看所有值:
print_r($jsonobj);
用于打印:
echo $jsonobj['status'];
对于博客内容,例如:
echo $jsonobj['blog_msgs'][0]['from_blogger_id'];