| Issue 316: | dynatree 1.21 RC3 does NOT support the default JSON format ??? => each pair is a string | |
| 1 person starred this issue and may be notified of changes. | Back to list |
When I use this json data hardcoded put into the html code the dynatree displays the treeitems and works correctly:
[{"title":"Root","key":1,"ParentId":null,"TemplateId":4,"children":[{"title":"Children1","key":2,"ParentId":1,"TemplateId":4,"children":[{"title":"Children1FromChildren1","key":4,"ParentId":2,"TemplateId":4,"children":[],"isFolder":false,"isLazy":false},{"title":"Children2FromChildren1","key":5,"ParentId":2,"TemplateId":4,"children":[],"isFolder":false,"isLazy":false}],"isFolder":true,"isLazy":false},{"title":"Children2","key":3,"ParentId":1,"TemplateId":4,"children":[{"title":"Children1FromChildren2","key":6,"ParentId":3,"TemplateId":4,"children":[],"isFolder":false,"isLazy":false},{"title":"Children2FromChildren2","key":7,"ParentId":3,"TemplateId":4,"children":[],"isFolder":false,"isLazy":false}],"isFolder":true,"isLazy":false}],"isFolder":true,"isLazy":false}]
When I get the exact same data from my asp.net mvc controller in the response.data which is bound to the dynatree then I get this error:
Please see the attached image where I made a screenshot of the exception!
May 27, 2012
#1
Bastienn...@googlemail.com
May 28, 2012
I have still attached an image where you see how I bind the response.data to the dynatree. Whey I copy out the exact same json you see in the images debug window and replace it with the data variable it works ??? I do not understand that...
May 28, 2012
JSON is a string (looks correct in your screenshot, except that key is typically a string too). But the 'children:' option expects a JavaScript object. This is generated by parsing JSON. If this doesn't happen, you might have forgotten to set the responses mimetype to application/json? You could also set the ajax option 'dataType' to json, or use http://api.jquery.com/jQuery.parseJSON/
Status:
Waiting
Labels: Milestone-Release1.2.1
May 28, 2012
Arghh... NOW I have seen it in another "debug window" the string has quotes around. So what is bad about a json string?
May 28, 2012
Forget about my last comment, you were faster. My key is an int in sql an auto incremented id. Should I have to convert it to a string? So the only problem you see with the children property? Hm... The error does not happen from server to client. Its a client binding problem that does not occur when I use the string hardcoded. But when I use the response.data then I see in my IDE that the content of data has double quotes around. Now I am confused.
May 28, 2012
OK I solved it. var jsarray = eval(data); Of course failure 50... ;-) Thanks. You can remove that "bug".
May 28, 2012
yes var jsonData = $.parseJSON(data); this is what I did after the eval() test ;-) but thanks. |