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

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

问题描述

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

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?

更新:我正在将带标签的树结构序列化为 JSON.所以从根开始,每个节点都嵌套它的子节点,然后嵌套它们的子节点......

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.

更新:我正在使用 org.json

UPDATE: I am using org.json

推荐答案

你不要说你使用的是哪个 JSON 包.这听起来像是一个有缺陷的(org.json 的默认值?我几乎希望它不存在)——30 是花生,绝对不应该引起问题.如果你有数千,我就明白为什么它会导致问题,但 30 应该没问题.所以考虑切换lib;如果您尽早解决简单的问题,通常会遇到许多其他问题.

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天全站免登陆