JSONArray jsonary = (JSONArray) JSONObject.parse(s); 是什么意思 jsonobject jsonobject = json.p...

JSONObject\u548cJSONArray\u7684\u533a\u522b\u662f\u4ec0\u4e48

JSON\u6709\u4e24\u79cd\u7ed3\u6784\uff1a\uff081\uff09\u5bf9\u8c61\u548c\uff082\uff09\u6570\u7ec4\u3002
\uff081\uff09\u5bf9\u8c61\u7ed3\u6784\u4ee5\u201d{\u201d\u5927\u62ec\u53f7\u5f00\u59cb\uff0c\u4ee5\u201d}\u201d\u5927\u62ec\u53f7\u7ed3\u675f\u3002\u4e2d\u95f4\u90e8\u5206\u75310\u6216\u591a\u4e2a\u4ee5\u201d\uff0c\u201d\u5206\u9694\u7684\u201dkey(\u5173\u952e\u5b57)/value(\u503c)\u201d\u5bf9\u6784\u6210\uff0c\u5173\u952e\u5b57\u548c\u503c\u4e4b\u95f4\u4ee5\u201d\uff1a\u201d\u5206\u9694\uff0c\u8bed\u6cd5\u7ed3\u6784\u5982\u4ee3\u7801\u3002
{
"1": "2",
"4": "5"
}
\u5176\u4e2d\u5173\u952e\u5b57\u662f\u5b57\u7b26\u4e32\uff0c\u800c\u503c\u53ef\u4ee5\u662f\u5b57\u7b26\u4e32\uff0c\u6570\u503c\uff0ctrue,false,null,\u5bf9\u8c61\u6216\u6570\u7ec4
\uff082\uff09\u6570\u7ec4\u7ed3\u6784\u4ee5\u201d[\u201d\u5f00\u59cb\uff0c\u201d]\u201d\u7ed3\u675f\u3002\u4e2d\u95f4\u75310\u6216\u591a\u4e2a\u4ee5\u201d\uff0c\u201d\u5206\u9694\u7684\u503c\u5217\u8868\u7ec4\u6210\uff0c\u8bed\u6cd5\u7ed3\u6784\u5982\u4ee3\u7801\u3002

[
{
"1": "2",
"4": "5"
},
{
"1": "2",
"4": "5"
}
]

\u4f60\u5e94\u8be5\u7528\u7684\u662ffastjson\u5427\uff01
JSONObject jsonObj = JSON.parseObject(str);//str\u662f\u4e2a\u5b57\u7b26\u4e32
\u53ef\u4ee5\u5c06str\u8f6c\u5316\u4e3a\u76f8\u5e94\u7684JSONObject\u5bf9\u8c61\uff0c\u5176\u4e2dstr\u662f\u201c\u952e\u503c\u5bf9\u201d\u5f62\u5f0f\u7684json\u5b57\u7b26\u4e32\uff0c\u8f6c\u5316\u4e3aJSONObject\u5bf9\u8c61\u4e4b\u540e\u5c31\u53ef\u4ee5\u4f7f\u7528\u5176\u5185\u7f6e\u7684\u65b9\u6cd5\uff0c\u8fdb\u884c\u5404\u79cd\u5904\u7406\u4e86\u3002

JSONObject.parse(s)
是调用JSONObject类的静态方法parse()方法将字符串格式的JSON数据s解析为JSON对象。

(JSONArray) JSONObject.parse(s)
将转换后的JSON对象强制转换为JSON数组(JSON对象的集合),因为s中可能包含多个JSON对象数据。

最终JSON数组是jsonary。

解析json格式的字符串,返回json数组

扩展阅读:java windowbuilder ... jennifer gibson ... javascript array ... jsonobject getjsonarray ... gibson les paul standard ... json server put ... jsonobject fromobject ... gentlemonster kun ... hypnotic poison ...

本站交流只代表网友个人观点,与本站立场无关
欢迎反馈与建议,请联系电邮
2024© 车视网