Reputation: 159
grid.getStore().getAt(0).data.ServiceDetails
Output:
"{brief: {"totalBilledUser":3}, details:{"totalBilledUser":3, "totalBilledUser1":3, "totalBilledUser2":3, "totalBilledUser3":3, "totalBilledUser4":3, "totalBilledUser5":3}}"
Please note that here the output starts with double quote.
JSON.parse(grid.getStore().getAt(0).data.ServiceDetails);
output Uncaught SyntaxError: Unexpected token b in JSON at position 1JSON.parse(JSON.stringify(grid.getStore().getAt(0).data.ServiceDetails))
It returns original string back.
Please guide me the proper way to get it as JSON object.
Upvotes: 0
Views: 92
Reputation: 11
the quotes are the problem, take a look:
"{ brief: { "totalBilledUser": 3 } }"
The first "
marks the beginning of the string, but the second "
instead of open the strinf for totalBilledUser
, closes the first "
.
Possible solutions are:
Open and close the output with single quotation marks '
.
'{ brief: { "totalBilledUser": 3 } }'
Escape the double quotes inside the output:
"{ brief: { \"totalBilledUser\": 3 } }"
Once you achieve one of the above solutions, you'll have, at least, a valid string. Now you can use JSON.stringify
and then JSON.parse
to transform it into JSON format. Hope I make myself clear.
Upvotes: 1