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
Add a ment  | 

2 Answers 2

Reset to default 5

You 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