删除JSONObject中的引号 [英] Removing quotation marks in JSONObject

查看:184
本文介绍了删除JSONObject中的引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用net.sf.json.JSONObject创建一些要发送到前端应用程序的数据,而我正在与之交互的代码不喜欢它为每个字段名称添加引号的方式。

I'm using the net.sf.json.JSONObject to create some data to be sent to a front end application, and the code I'm interacting with doesn't like the ways its adding quotation marks to every field name.

例如:

 myString = new JSONObject().put("JSON", "Hello, World!").toString();

生成字符串{JSON:Hello,World}。

produces the string {"JSON": "Hello, World"}.

我希望它返回的是{JSON:你好,世界} - 没有引号围绕JSON。我该怎么做才能实现这一目标?

What I want it to return is {JSON: "Hello, World"} - without quotes around "JSON". What do I have to do to make that happen?

推荐答案

javadoc


toString
方法生成的文本严格符合JSON
sysntax规则。

The texts produced by the toString methods strictly conform to the JSON sysntax rules.

如果你想要符合JSON语法规则,你不要删除引号。

If you want to conform to the JSON syntax rules, you shouln't remove the quotes.

或者如果你不关心规则,你可以创建你自己的简单构造这个字符串的方法。

Or if you don't care about the rules, you could create you own simple method to contruct this strings.

另外,替换2个第一次出现的引号是有效的,如@CharlesLeaf所说。

Also, replace the 2 first occurrences of the quotes is valid, as @CharlesLeaf said.

这篇关于删除JSONObject中的引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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