Hi. I got my output in JSON... Now I need to convert those data into javascript..
How to write the code in javascript? I have to display the images to the browser.. it is possible only by writing the code in javascript. Help me..
My JSON output is..
[{"0":"101","member_id":"101","1":"3k.png","image_nm":"3k.png","2":"\/images\/phones\/","image_path":"\/images\/phones\/"},
{"0":"102","member_id":"102","1":"mirchi.png","image_nm":"mirchi.png","2":"images\/phones\/","image_path":"images\/phones\/"},
{"0":"103","member_id":"103","1":"masti.png","image_nm":"masti.png","2":"images\/phones\/","image_path":"images\/phones\/"}]
Convert JSON to Array Using `json.The parse() function takes the argument of the JSON source and converts it to the JSON format, because most of the time when you fetch the data from the server the format of the response is the string. Make sure that it has a string value coming from a server or the local source.
JSON can be either an array or an object.
Stringify a JavaScript ArrayIt is also possible to stringify JavaScript arrays: Imagine we have this array in JavaScript: const arr = ["John", "Peter", "Sally", "Jane"]; Use the JavaScript function JSON.
JSON.stringify() The JSON.stringify() method converts a JavaScript value to a JSON string, optionally replacing values if a replacer function is specified or optionally including only the specified properties if a replacer array is specified.
hai i got my output in JSON...now i need to convert those data into javascript..
Use JSON.parse()
function in order to convert it to JS object.
var obj = JSON.parse(yourJsonString);
And now you can use for-in
loop to iterate over each of its items:
for (var x in obj){
if (obj.hasOwnProperty(x)){
// your code
}
}
If you are using jQuery you can use
var object = $.parseJSON(jsonstring);
Or add this library https://raw.github.com/douglascrockford/JSON-js/master/json2.js and give
var object = JSON.parse(jsonstring);
you should be able to use it as an object, which supports all of the key functions of an array
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With