-3

We have a link at the end of which is a lot of JSON. How can we turn the contents of the link into a string, and then render that JSON as objects?

EDIT We have decided to use other methods, but thank you for your help. We have accepted the answer we found most useful

2
  • What have you tried? What is the JSON like? Are you having trouble rendering the JSON, or using the API to get the JSON? Commented Jul 29, 2015 at 14:30
  • When you are try to ask something please post it clearly we cant suggest you the correct answer with this two line Commented Jul 29, 2015 at 14:30

4 Answers 4

2

This is the only answer I can give with the amount of info you provided

document.body.innerHTML = jsonData.toString();

EDIT: alternativly if its a regular JS object you would need to do:

document.body.innerHTML = JSON.stringify(jsonData);

I hope this helps

Sign up to request clarification or add additional context in comments.

2 Comments

I agree that the question is terribly vague, but the result of calling .toString() on a typical object is the string [object Object] and not any interesting rendering of a data structure.
yes, I have added another possibility to my Answer if its an actual object :)
0

You could try something like that to show complex JSON to a user, with indent:

var pre = document.createElement("pre");
var textNode = document.createTextNode(JSON.stringify(someObject, null, 4));
pre.appendChild(textNode);
document.body.appendChild(pre);

Comments

0

Possible Duplicate of :Rendering json using jquery.

  1. or try var myJSONObject = JSON.parse(myJSONString);
  2. var jsonString = JSON.stringify(myJsonObject);

1 Comment

you forgot to add the actual rendering part :)
0

Try this way,,

document.body.innerHTML = JSON.stringify(jsondata);

This may help you

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.