Question:
Json request with Javascript?
Sam
2011-01-05 12:14:10 UTC
down vote favorite


Hi, I am just beginner on java script and JSON and never had done any work in these before. My employer has just asked me to create the basic POC of these.
Scenario: I have a REST API and when i call it, it returns back response in JSON format.
Need to To: Create a HTML page and use javascript to call that REST API and capture JSON response and print in the same HTML page.



I would appreciate your help. This might be simple, but for me i have no idea because i never have done anything similar in java script and json. I goggled but could not find anything.

Thanks,
Three answers:
?
2011-01-05 12:16:05 UTC
Is the REST API an external javascript file? Or is a web service - what is the rest API returning?



** Nevermind - I see that it is returning a JSON string.



You will need to take the JSON string the REST API returns and parse it into a JSON object.



Click here for ref: https://github.com/douglascrockford/JSON-js



This is what a json string to json object syntax looks like



var myJson = '{ "x": "Hello, World!", "y": [1, 2, 3] }';



var myJsonObj = jsonParse(myJson);alert(myJsonObj.x);

// alerts Hello, World!



for (var k in myJsonObj) {

// alerts x=Hello, World! and y=1,2,3

alert(k + '=' + myJsonObj[k]);

}
?
2016-11-08 06:48:01 UTC
you haven't any longer likely defined your challenge nicely. Parsing JSON is a non-journey as a results of fact it rather is JavaScript merchandise Notation. only have it in a SCRIPT tag and you're golden. in case you get it from an AJAX request, assuming you haven't any longer have been given some framework coping with it for you, only bypass the string to the eval() function and catch the return. in case you elect greater particular supply help to could desire to grant greater particular difficulty info. EDIT: No, you probably did no longer rather let us know what the blunders is or the place you're breaking down. i'm no longer looking over your shoulder so i can not rather debug issues for you effectively until you may narrow the difficulty down adequate to ask a pointed and direct question.
Udit
2014-02-11 23:00:34 UTC
try this online free services for json parsing and converting into other format

online-formatconverter.rhcloud.com/converter/jsontoexcel.jsp


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...