I have a C# class that I want to convert to a JSON string, send it to my web client and using jQuery, parse that into an array of JSON objects. Is that possible?
here is some example code
class mnuitm
{
public string prop1;
public string prop2;
public List<mnuitm> children;
}
I am trying to build a string that looks like this:
{
"prop1":"value in prop1",
"prop2":"value in prop2",
"children":[
{
"prop1":"value in prop1",
"prop2":"value in prop2"
},
{
"prop1":"value in prop1",
"prop2":"value in prop2"
}
]
}, ... (repeat n times, children may not be there or have any number of child items
} //closing bracket
my client makes an ajax call which returns the above as a string
and I’m trying to parse it with jQuery, but it isn’t working.
Is this possible. If not, how should I do it
Thx
Use
jQuery.getJSON()http://api.jquery.com/jQuery.getJSON/
Alternatively, you can just do
JSON.parse(str)in the browsers that support it (I know Chrome/FF4 for sure). For better cross-browser support, usejQuery.parseJSON().http://api.jquery.com/jQuery.parseJSON/