admin管理员组文章数量:1025457
So after receiving my response, I keep getting a parse error. Is there such thing as illegal characters?
Here is the response
[{"businessID": ChIJ49DlQ5NiwokRQ_noyKqlchQ,"latitude": 40.733038,"longitude":-73.6840691,"address":"1201
Jericho Turnpike, New Hyde Park","businessname":"SUBWAY®Restaurants"},{"businessID": ChIJZfl6R5NiwokRZo7PU4NPoMY
,"latitude": 40.7329359,"longitude":-73.684513,"address":"1113 Jericho Turnpike, New Hyde Park","businessname"
:"Gino's"},{"businessID": ChIJcbpnRJNiwokRrtbOKe7HQo0,"latitude": 40.733049,"longitude":-73.684006,"address"
:"1203 Jericho Turnpike, New Hyde Park","businessname":"Wong's Garden"},]
Here is my function that handles the response. I know for sure its breaking before the alert because the alert is not being triggered
var datad = $(msg).text();
console.log(datad);
var resultstring = datad.replace(',]',']');
var JsonParseData = JSON.parse(resultstring);
alert(JsonParseData); ///BREAKING BEFORE THIS LINE
So after receiving my response, I keep getting a parse error. Is there such thing as illegal characters?
Here is the response
[{"businessID": ChIJ49DlQ5NiwokRQ_noyKqlchQ,"latitude": 40.733038,"longitude":-73.6840691,"address":"1201
Jericho Turnpike, New Hyde Park","businessname":"SUBWAY®Restaurants"},{"businessID": ChIJZfl6R5NiwokRZo7PU4NPoMY
,"latitude": 40.7329359,"longitude":-73.684513,"address":"1113 Jericho Turnpike, New Hyde Park","businessname"
:"Gino's"},{"businessID": ChIJcbpnRJNiwokRrtbOKe7HQo0,"latitude": 40.733049,"longitude":-73.684006,"address"
:"1203 Jericho Turnpike, New Hyde Park","businessname":"Wong's Garden"},]
Here is my function that handles the response. I know for sure its breaking before the alert because the alert is not being triggered
var datad = $(msg).text();
console.log(datad);
var resultstring = datad.replace(',]',']');
var JsonParseData = JSON.parse(resultstring);
alert(JsonParseData); ///BREAKING BEFORE THIS LINE
Share
Improve this question
edited Jul 18, 2017 at 4:21
Saumini Navaratnam
8,9005 gold badges46 silver badges74 bronze badges
asked Jul 18, 2017 at 3:50
CarlitosCarlitos
4194 silver badges20 bronze badges
6
- 2 double quote the value of businessID in the object – Mantu Nigam Commented Jul 18, 2017 at 3:54
- 1 also there's a trailing ma – anthony sottile Commented Jul 18, 2017 at 3:57
- @AnthonySottile Im removing the ma at line....var resultstring = datad.replace(',]',']'); – Carlitos Commented Jul 18, 2017 at 3:58
- Java is not Javascript. Please be careful about using the right tag. I've fixed it. – ajb Commented Jul 18, 2017 at 4:02
- 1 Looks like you have random new line chars in "address" part and missing quotation marks in variable resultstring, in "businessID" part. You can check the JSON formatting here: ietf/rfc/rfc4627.txt – vishwarajanand Commented Jul 18, 2017 at 4:03
3 Answers
Reset to default 5Couple of mistakes.
Need to puth the string in double quotes(
"
). Replace"businessID": ChIJ49DlQ5NiwokRQ_noyKqlchQ
with"businessID":"ChIJ49DlQ5NiwokRQ_noyKqlchQ"
Remove the
,
at the end of following line"businessname":"Wong's Garden"},]
The key values of JSON require quotation marks. You have fewer quotes in the JSON data, and at last you have one more ma and one more carriage return
like this is right:
[{"businessID":"ChIJ49DlQ5NiwokRQ_noyKqlchQ","latitude":"40.733038","longitude":"-73.6840691","address":"1201 Jericho Turnpike, New Hyde Park","businessname":"SUBWAY®Restaurants"},{"businessID":"ChIJZfl6R5NiwokRZo7PU4NPoMY","latitude":"40.7329359","longitude":"-73.684513","address":"1113 Jericho Turnpike, New Hyde Park","businessname":"Gino's"},{"businessID":"ChIJcbpnRJNiwokRrtbOKe7HQo0","latitude":"40.733049","longitude":"-73.684006","address":"1203 Jericho Turnpike, New Hyde Park","businessname":"Wong's Garden"}]
Your response is an invalid json format for 2 reasons:
- The values of the "businessID" requires quotation marks.
- There should not be a ma after the last object of the JSON (your replace string function fix this).
I remend you to use this JSON toolkits:
- http://jsonviewer.stack.hu/ (This orders my json although is incorrect)
- https://jsonformatter/ (I use this a lot, my favorite)
So after receiving my response, I keep getting a parse error. Is there such thing as illegal characters?
Here is the response
[{"businessID": ChIJ49DlQ5NiwokRQ_noyKqlchQ,"latitude": 40.733038,"longitude":-73.6840691,"address":"1201
Jericho Turnpike, New Hyde Park","businessname":"SUBWAY®Restaurants"},{"businessID": ChIJZfl6R5NiwokRZo7PU4NPoMY
,"latitude": 40.7329359,"longitude":-73.684513,"address":"1113 Jericho Turnpike, New Hyde Park","businessname"
:"Gino's"},{"businessID": ChIJcbpnRJNiwokRrtbOKe7HQo0,"latitude": 40.733049,"longitude":-73.684006,"address"
:"1203 Jericho Turnpike, New Hyde Park","businessname":"Wong's Garden"},]
Here is my function that handles the response. I know for sure its breaking before the alert because the alert is not being triggered
var datad = $(msg).text();
console.log(datad);
var resultstring = datad.replace(',]',']');
var JsonParseData = JSON.parse(resultstring);
alert(JsonParseData); ///BREAKING BEFORE THIS LINE
So after receiving my response, I keep getting a parse error. Is there such thing as illegal characters?
Here is the response
[{"businessID": ChIJ49DlQ5NiwokRQ_noyKqlchQ,"latitude": 40.733038,"longitude":-73.6840691,"address":"1201
Jericho Turnpike, New Hyde Park","businessname":"SUBWAY®Restaurants"},{"businessID": ChIJZfl6R5NiwokRZo7PU4NPoMY
,"latitude": 40.7329359,"longitude":-73.684513,"address":"1113 Jericho Turnpike, New Hyde Park","businessname"
:"Gino's"},{"businessID": ChIJcbpnRJNiwokRrtbOKe7HQo0,"latitude": 40.733049,"longitude":-73.684006,"address"
:"1203 Jericho Turnpike, New Hyde Park","businessname":"Wong's Garden"},]
Here is my function that handles the response. I know for sure its breaking before the alert because the alert is not being triggered
var datad = $(msg).text();
console.log(datad);
var resultstring = datad.replace(',]',']');
var JsonParseData = JSON.parse(resultstring);
alert(JsonParseData); ///BREAKING BEFORE THIS LINE
Share
Improve this question
edited Jul 18, 2017 at 4:21
Saumini Navaratnam
8,9005 gold badges46 silver badges74 bronze badges
asked Jul 18, 2017 at 3:50
CarlitosCarlitos
4194 silver badges20 bronze badges
6
- 2 double quote the value of businessID in the object – Mantu Nigam Commented Jul 18, 2017 at 3:54
- 1 also there's a trailing ma – anthony sottile Commented Jul 18, 2017 at 3:57
- @AnthonySottile Im removing the ma at line....var resultstring = datad.replace(',]',']'); – Carlitos Commented Jul 18, 2017 at 3:58
- Java is not Javascript. Please be careful about using the right tag. I've fixed it. – ajb Commented Jul 18, 2017 at 4:02
- 1 Looks like you have random new line chars in "address" part and missing quotation marks in variable resultstring, in "businessID" part. You can check the JSON formatting here: ietf/rfc/rfc4627.txt – vishwarajanand Commented Jul 18, 2017 at 4:03
3 Answers
Reset to default 5Couple of mistakes.
Need to puth the string in double quotes(
"
). Replace"businessID": ChIJ49DlQ5NiwokRQ_noyKqlchQ
with"businessID":"ChIJ49DlQ5NiwokRQ_noyKqlchQ"
Remove the
,
at the end of following line"businessname":"Wong's Garden"},]
The key values of JSON require quotation marks. You have fewer quotes in the JSON data, and at last you have one more ma and one more carriage return
like this is right:
[{"businessID":"ChIJ49DlQ5NiwokRQ_noyKqlchQ","latitude":"40.733038","longitude":"-73.6840691","address":"1201 Jericho Turnpike, New Hyde Park","businessname":"SUBWAY®Restaurants"},{"businessID":"ChIJZfl6R5NiwokRZo7PU4NPoMY","latitude":"40.7329359","longitude":"-73.684513","address":"1113 Jericho Turnpike, New Hyde Park","businessname":"Gino's"},{"businessID":"ChIJcbpnRJNiwokRrtbOKe7HQo0","latitude":"40.733049","longitude":"-73.684006","address":"1203 Jericho Turnpike, New Hyde Park","businessname":"Wong's Garden"}]
Your response is an invalid json format for 2 reasons:
- The values of the "businessID" requires quotation marks.
- There should not be a ma after the last object of the JSON (your replace string function fix this).
I remend you to use this JSON toolkits:
- http://jsonviewer.stack.hu/ (This orders my json although is incorrect)
- https://jsonformatter/ (I use this a lot, my favorite)
本文标签: javascriptWhat characters arent allowed in a JSONparseStack Overflow
版权声明:本文标题:javascript - What characters arent allowed in a JSON.parse? - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745636788a2160499.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论