gpt4 book ai didi

java - 使用JAVA创建一个空的json字段

转载 作者:行者123 更新时间:2023-12-02 01:09:40 24 4
gpt4 key购买 nike

我想生成这样的 JSON:

{ “index”:{} }

这是我正在使用的代码:

JSONObject indexObject = new JSONObject( );
indexObject.put( "index", new JSONArray());

但它输出:

{"index":[]}

最佳答案

发生这种情况是因为您将 JSONArray() 放在那里。尝试像这样放置 JSONObject() :

indexObject.put( "index", new JSONObject());

谢谢,@bhusak。

关于java - 使用JAVA创建一个空的json字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57698144/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com