-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
  • 319,460
  • 37
  • 290
  • 318
sandeep
  • 439
  • 1
  • 6
  • 20
  • `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
  • 666,277
  • 106
  • 705
  • 986
0

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

Prasanna Kumar H A
  • 3,153
  • 4
  • 22
  • 49