Convert a JSON String into JavaScriptObject

Converting a JSON String in to a JavaScriptObject can be pretty easy. Either you can do it in javascript file, or, simply use a native method for that.
The code will as simple as follows:

var temp = jsonString;
var jsonObject = eval('('+temp+')');
return jsonObject
This program will return the JavasScriptObject.
But, if you want to return the JSON String , remove the previous return statement & add the the below line :

return JSON.stringify(jsonObject);

This return statement will convert your JavaScript Object in JSON String & return it.



Happy Learning!!

No comments :

Post a Comment