nesting too deep in JSON… should I switch to XML?

主宰稳场 提交于 2019-12-09 03:39:07

问题


I am getting a JSONException complaining about a very deep nesting (more than 30). I know that the value is hardcoded in JSONWriter. what best can I do? use another library without this restriction if such thing exists? switch to XML?

UPDATE: I am serializing a labeled tree structure into JSON. So starting with root, each node is nesting its children which in turn nesting theirs...

{"type":"n1","links":[{"label":"l1","target":{"type":"n2","links":[{"label":"l2","target":{  ...}}]}}]}

I might have to rethink the way I am serializing my object structure.

UPDATE: I am using org.json


回答1:


You don't say which JSON package you are using. It sounds like a defective one (org.json's default one? I almost wish it didn't exist) -- 30 is peanuts, absolutely should not cause problems. If you had thousands I could see why it could lead to problems, but 30 should be no problem. So consider switching the lib; usually you have many other issues if you hit into simple ones early on.




回答2:


You may ask yourself if such a deep nesting makes sense at all. Is it really needed? Maybe you could give us an example why you'd need such a deep nesting.



来源:https://stackoverflow.com/questions/3660509/nesting-too-deep-in-json-should-i-switch-to-xml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!