关于 java JSONArray JSONObject转换问题

关于 java JSONArray JSONObject转换问题importlhy.client.json.JSONArray;importlhy.client.json.JSONException;importlhy.client.json.JSONObject;publicclassMyJson{publicstaticvoidmain(String[]args)throwsJSO…

大家好,又见面了,我是你们的朋友全栈君。

import lhy.client.json.JSONArray;

import lhy.client.json.JSONException;

import lhy.client.json.JSONObject;

public class MyJson {

public static void main(String[] args) throws JSONException {

JSONArray ja=new JSONArray();

JSONObject jo=new JSONObject();

jo.put(“1”, “a”);

jo.put(“2”, “b”);

//ja.put(jo);此处不能写为jo.toString(),

ja.put(jo.toString());//如果写成jo.toString()输出ja显示为[“{\”1\”:\”a\”}”]

System.out.println(ja);

for(int i=0;i<ja.length();i++){

//如果在加入JSONArray时,写为jo.toString(),会报错:JSONException: JSONArray[0] is not a JSONObject.

System.out.println(ja.getJSONObject(i));

}

}

}

关于 java JSONArray JSONObject转换问题

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/137613.html原文链接:https://javaforall.net

赞 (0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号