Question

I am new to javascript and I have loaded in a json object onto my site using canJS. The json is pretty long (>1000) lines and a fairly complex nested structure. Is there a way to load in the object so I can access the fields and subobjects?

I load in the object to an <li> element then I pass that element into another function. The problem is when it gets to that function I am unable to access the fields. When I look at the developer tools it has the textContext name defined correctly. Should I not be passing the <li>? What object do I pass to my function to manipulate the json object I retrieved using my service?

EDIT: How can I use json.Parse in canJs findAll()?

FYI: Using canjs library, c# 4.0 backend service, json is loaded from mongodb. I have seen that the correct object is returned in chrome developer tools

Was it helpful?

Solution

Simply use JSON.parse :JSON.parse

demo example :

var jsontext = '{"firstname":"Jesper","surname":"Aaberg","phone":["555-0100","555-0120"]}';
var contact = JSON.parse(jsontext);
document.write(contact.surname + ", " + contact.firstname);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top