【仅供内部供应商使用,不提供对外解答和培训】

Page tree

【仅供内部供应商使用,不提供对外解答和培训】

Skip to end of metadata
Go to start of metadata

JSON操作

创建一个空的JSONObject对象

 

com.fr.json.JSONObject jo = com.fr.json.JSONObject.create();

 

创建一个空的JSONArray对象(数组)

 

com.fr.json.JSONArray array = com.fr.json.JSONArray.create();

 

将JSON格式的字符串转为Java可解析的JSONObject对象

 

String txt = "{\"a\":\"你好\"}";
com.fr.json.JSONObject jo = new com.fr.json.JSONObject(txt);
System.out.println(jo.optString("a"));//将输出"你好"

 

将JSON格式的字符串转为Java可解析的JSONArray对象

 

String txt = "[{\"a\":\"你好\"}, {\"b\":\"大家好\"}]";
com.fr.json.JSONArray array = new com.fr.json.JSONArray(txt);
  • No labels