使用PHP发回json值时发生意外错误 [英] Unexpected error when posting back json value using PHP
本文介绍了使用PHP发回json值时发生意外错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Ajax将一些数据从服务器端代码PHP发送回客户端,这是完成的操作
I am posting back some data from my server side code PHP to my client side using Ajax , this is how its done
//server side
$json="{
"payout_history":"0",
"round_shares":"1816",
"workers":
{
"jbo.5970":
{
"alive":"1",
"hashrate":"1253"
},
"jbo.5970cpu":
{
"alive":"1",
"hashrate":"21"
},
"jbo.5970-2":
{
"alive":"1",
"hashrate":"1062"
}
}
}";
echo json_encode($json);
我在萤火虫的响应页面中收到此错误,我无法弄清它是怎么了
I am getting this error in the response page of firebug and i cant figure out whats wrong with it
<br />
<b>Parse error</b>: syntax error, unexpected 'payout_history' (T_STRING) in
<b>C:\xampp\htdocs\exercise5json\display.php</b> on line <b>38</b><br />
推荐答案
您没有正确嵌套引号.您需要将JSON字符串括在单引号中,而不是双引号中:
You're not nesting the quotes properly. You need to enclose your JSON string in single quotes, not double quotes:
$json = '{"myTag":"myData"}';
更好-将数组创建为PHP数组,并使用json_encode()
为您生成JSON.
Or better - create the array as a PHP array and use json_encode()
to produce the JSON for you.
这篇关于使用PHP发回json值时发生意外错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文