无法解析我的Phonegap项目中的JSON字符串错误 [英] Unable to parse JSON string error in my Phonegap project
本文介绍了无法解析我的Phonegap项目中的JSON字符串错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,我从PHP获取JSPN时遇到问题,如下所示:
Hello, I''m having problems while getting JSPN from PHP, shown below:
[{
"vehicleId": "1",
"status": "Running",
"position": "x",
"battery": "25",
"distanceTravelled": "123",
"destination": "y",
"freeSeats": "2",
"speed": "32"
}
]
But, my new version of my code it is comes like that (without quotes in number values) and it gives a parse Json error and it doen't shown anything.
[{
"vehicleId": 1,
"status": "Running",
"position": "x",
"battery": 25,
"distanceTravelled": 123,
"destination": "y",
"freeSeats": 2,
"speed": 32
}
]
我检查了jsonlint的格式.com,它是有效的。 Eclipse中的日志错误是:
I checked the format at jsonlint.com and it is valid. The error in log in Eclipse is:
05-09 21:37:25.536: E/Web Console(336): SyntaxError: Unable to parse JSON string at file:///android_asset/www/MobileMan.js:37
34 xmlhttp.open("GET",url,false);
35 xmlhttp.send();
36 var json = xmlhttp.responseText;
37 obj = JSON.parse(json);
我还在Chrome上的计算机上尝试过Javascript代码工作良好。我无法解决问题。谢谢你的回答。
I also tried the Javascript code in my computer on Chrome and everything works fine. I couldn''t resolve the problem. Thanks for your answers.
推荐答案
尝试删除双引号
Try by removing double quote
"vehicleId" as vehicleId
[
{
vehicleId: "1",
status: "Running",
position: "x",
battery: "25",
distanceTravelled: "123",
destination: "y",
freeSeats: "2",
speed: "32"
}
]
这篇关于无法解析我的Phonegap项目中的JSON字符串错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文