My favorites | Sign in
Project Home Downloads
READ-ONLY: This project has been archived. For more information see this post.
Search
for
  Advanced search   Search tips   Subscriptions
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
Status:  Done
Owner:  ----
Closed:  May 2012


 
Reported by Bastienn...@googlemail.com, May 27, 2012
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!



exception.json.wrong.data.format.PNG
59.0 KB   View   Download
May 27, 2012
#1 Bastienn...@googlemail.com
I use IE9. In Google Chrome 19 I get no exception but my TreeDiv is empty although a long vertical scrollbar is shown.
May 28, 2012
#2 Bastienn...@googlemail.com
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...
errorWithDataBinding.png
29.3 KB   View   Download
May 28, 2012
Project Member #3 moo...@wwwendt.de
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
#4 Bastienn...@googlemail.com
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
#5 Bastienn...@googlemail.com
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
#6 Bastienn...@googlemail.com
OK I solved it.  var jsarray = eval(data);
Of course failure 50... ;-) Thanks. You can remove that "bug".
May 28, 2012
Project Member #7 moo...@wwwendt.de
btw. http://api.jquery.com/jQuery.parseJSON/ is recommended over eval()
Status: Done
May 28, 2012
#8 Bastienn...@googlemail.com
yes  var jsonData = $.parseJSON(data); this is what I did after the eval() test ;-) but thanks.

Powered by Google Project Hosting