How to display all array values from json in PHP?

php json

50 просмотра

1 ответ

i am currently having problem displaying all array values for a particular type i am trying to fetch all the messages from the json

Here is my code:

<?php
$request = 'https://devblogs.instavoice.com';
$response  = file_get_contents($request);
$jsonobj  = json_decode($response,true);
echo $jsonobj->status;
echo $jsonobj[0]->msg_content;
?>

Here is the json i am trying to fetch :

{"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}

I am having difficulty displaying all the messages on "msg_content" but it returns error.

Автор: rahul kapoot Источник Размещён: 08.11.2019 10:59

Ответы (1)


1 плюс

To see all values:

print_r($jsonobj);

For print:

echo $jsonobj['status'];

For blog content, example:

echo $jsonobj['blog_msgs'][0]['from_blogger_id'];
Автор: Ionuț Popescu Размещён: 20.08.2016 07:15
Вопросы из категории :
32x32