【发布时间】:2015-12-11 23:40:02
【问题描述】:
对此我感到非常沮丧,并且可以使用一些精明的头脑。 我正在构建一个相对简单的 API。 使用 PHP 创建了 stdClass() 和 json_encode。 在主机服务器上,数据完美呼应。 在客户端我得到一个持久的 foreach 无效参数错误。
$thefez= new stdClass();
$thefez->muid=$id;
$thefez->bandname=$bandname;
$thefez->core=new stdClass();
$thefez->core->joined=$since;
$thefez->core->bandbio=$bio;
$thefez->core->genre=$genre;
$thefez->core->subgenre=$subgenre;
echo json_encode($thefez);
结果(主机)
{"muid":"IM5LGM02MFS8RJLKGY9W","bandname":"Marbles For Zen","core":
{"joined":"Sun 01 March 2015","bandbio":"Zen And Marbles","genre":"Rhythm Blues",
"subgenre":"Dixie Rhythm"}}
{"muid":"IMA3YNBKZQDNR9RBCSRI","bandname":"Frankie Storm","core":
{"joined":"Sat 21 February 2015","bandbio":"Just registered. Bio coming soon.","genre":"Popular","subgenre":""}}
问题: 使用 json_decode 和 foreach 只是想回显数组中的项目。
json_decode(file_get_contents('http://api.mutrs.me/?artists'), TRUE);
foreach($result as $item){
$item->muid;
}
主持人:
检查 json_last_error 它返回 0
检查 json_last_error_msg 它返回 No Error
客户:
检查 json_last_error 它返回 4
检查 json_last_error_msg 它返回 语法错误
【问题讨论】: