admin管理员组文章数量:1290287
My JSON string,
JSON.parse('{"start_date_time": ["2012-12-05 04:45:42.135000", "None"], "terminal_no": ["T1081", "None"], "master_doc_no": ["100008", "100008"], "notes": ["", ""], "doc_no": ["1000018", "1000019"], "location_code": ["1005", "1005"], "end_date_time": ["2012-12-05 05:27:04.529000", "None"], "doc_status": ["CC Ended", "Draft"], "bc_list": ["[{\"465\":\"85\"},{\"306\":\"6\"},{\"306\":\"47\"},{\"306\":\"366\"},{\"306\":\"634\"}]", "[{\"257\":\"14\"}]"]}')
But its throwing SyntaxError: Unexpected Number
Where am i wrong over here?
My JSON string,
JSON.parse('{"start_date_time": ["2012-12-05 04:45:42.135000", "None"], "terminal_no": ["T1081", "None"], "master_doc_no": ["100008", "100008"], "notes": ["", ""], "doc_no": ["1000018", "1000019"], "location_code": ["1005", "1005"], "end_date_time": ["2012-12-05 05:27:04.529000", "None"], "doc_status": ["CC Ended", "Draft"], "bc_list": ["[{\"465\":\"85\"},{\"306\":\"6\"},{\"306\":\"47\"},{\"306\":\"366\"},{\"306\":\"634\"}]", "[{\"257\":\"14\"}]"]}')
But its throwing SyntaxError: Unexpected Number
Where am i wrong over here?
Share Improve this question asked Dec 15, 2012 at 4:46 Niks JainNiks Jain 1,6475 gold badges27 silver badges53 bronze badges 2- Validates just fine using JSONLint: jsonlint. Is there any more information about the error? – Hunter McMillen Commented Dec 15, 2012 at 4:49
-
@HunterMcMillen, The error definitely occurs. Throw it in your browser console. It has to do with
bc_list
data. – Brad Commented Dec 15, 2012 at 5:01
2 Answers
Reset to default 5You can start by simplifying this down to where the problem occurs, in bc_list
...
JSON.parse('{"bc_list": ["", "{\"257\":\"14\"}]"]}')
The issue is that your backslashes are being considered for the outer quotes on JSON.parse()
instead of the inner data. You must escape the backslashes as well.
JSON.parse('{"bc_list": ["", "{\\"257\\":\\"14\\"}]"]}')
Your whole line fixed bees:
JSON.parse('{"start_date_time": ["2012-12-05 04:45:42.135000", "None"], "terminal_no": ["T1081", "None"], "master_doc_no": ["100008", "100008"], "notes": ["", ""], "doc_no": ["1000018", "1000019"], "location_code": ["1005", "1005"], "end_date_time": ["2012-12-05 05:27:04.529000", "None"], "doc_status": ["CC Ended", "Draft"], "bc_list": ["[{\\"465\\":\\"85\\"},{\\"306\\":\\"6\\"},{\\"306\\":\\"47\\"},{\\"306\\":\\"366\\"},{\\"306\\":\\"634\\"}]", "[{\\"257\\":\\"14\\"}]"]}')
Don't use JSON data within strings within JSON data. It's a mess.
This normally means your you are missing an operator, or have an illegal operator, in a calculation.
For example:
var a = 1000 * 1000; // correct
var b = 1000 1000; // incorrect
var c = 1234; // correct
var d = 1,234; // incorrect
vars b and d will result in:
Uncaught SyntaxError: Unexpected number
本文标签: javascriptSyntaxError Unexpected Number (JSONparse)Stack Overflow
版权声明:本文标题:javascript - SyntaxError: Unexpected Number (JSON.parse) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741495954a2381838.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论