-3

I am getting my JSON string as:

newStr = { total:"1", page:"1", records:"2", rows: [<li>a</li><li>b</li>] }.
jQuery("#list").addJSONData(JSON.parse(newStr)); 
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
sandeep
  • 449
  • 2
  • 7
  • 22
  • `newStr` appears to already be an object, not a string, hence why `JSON.parse` is throwing an error. You can remove that method call. – Rory McCrossan Apr 13 '15 at 09:27

2 Answers2

2

You are trying to parse something that is not a string. This will implicitly call toString on the object, and you get the string [object Object], which is not valid JSON.

Either parse a string:

newStr = '{"total":"1","page":"1","records":"2","rows":["<li>a</li>", "<li>b</li>"]}';
jQuery("#list").addJSONData(JSON.parse(newStr)); 

or use the object:

newStr = { total:"1", page:"1", records:"2", rows: ["<li>a</li>", "<li>b</li>"] };
jQuery("#list").addJSONData(newStr); 
Guffa
  • 687,336
  • 108
  • 737
  • 1,005
0

You are trying put a json data as Json data,remove JSON.parse it will work

Prasanna Kumar H A
  • 3,341
  • 6
  • 24
  • 52