在JSON中嵌套太深...我应该切换到XML吗? [英] nesting too deep in JSON... should I switch to XML?

查看:453
本文介绍了在JSON中嵌套太深...我应该切换到XML吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到一个JSONException,抱怨一个很深的嵌套(超过30个)。我知道这个值在JSONWriter中是硬编码的。
我最能做什么?如果这样的事情存在,使用另一个库没有此限制?切换到XML?



更新:
我将带标签的树结构序列化为JSON。所以从root开始,每一个节点都嵌套了它的子节点,这个子节点依次嵌套它们的...

  {type:n1 ,links:[{label:l1,target:{type:n2,links:[{label:l2,target我可能需要重新思考序列化我的对象结构的方式。 。



更新:我正在使用org.json

解决方案

你不说你使用哪个JSON包。这听起来像一个有缺陷的(org.json的默认的一个,我几乎希望它不存在) - 30是花生,绝对不应该导致问题。如果你有成千上万的我可以看到为什么会导致问题,但30应该没有问题。
所以考虑切换lib;通常你有很多其他问题,如果你早点进入简单的。


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

解决方案

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.

这篇关于在JSON中嵌套太深...我应该切换到XML吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆