关于json的小例子

xiaoxiao2021-02-28  68

今天用到了java  json  以前也有用到  就是没有写下来的好习惯

import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; public class Test { public static void main(String[] args) { String str="{'name':xiaoming;'age':20;'tongxue':[{'laoda':大菊},{'laoer':二局},{'laosan':三局},{'laosi':四局}]}"; try { JSONObject json= new JSONObject(str);  System.out.println(json.get("name")); System.out.println("age"); JSONArray js  = json.getJSONArray("tongxue"); JSONObject bb= (JSONObject)js.get(0); System.out.println(bb.get("laoda")); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }

很精髓 ,只需要这个json的jar包即可

转载请注明原文地址: https://www.6miu.com/read-40977.html

最新回复(0)