加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ORG.json处理

发布时间:2020-12-16 19:19:43 所属栏目:百科 来源:网络整理
导读://使用new JSONObject()构造一个JSON对象,参数为空 public String jsonTest() throws JSONException{ JSONObject json= new JSONObject(); JSONArray jsonMembers = JSONArray(); JSONObject member1 = JSONObject(); member1.put( "loginname" , "jack" );
//使用new JSONObject()构造一个JSON对象,参数为空
public String jsonTest() throws JSONException{
JSONObject json= new JSONObject();
JSONArray jsonMembers = JSONArray();
JSONObject member1 = JSONObject();
member1.put( "loginname" , "jack" );
"password" "userpass" );
"email" "fbeiwb@163.com" );
"sign_date" "2007-06-12" );
jsonMembers.put(member1);
JSONObject member2 = JSONObject();
member2.put( "tom" );
);
"123123@126.com" );
"2008-07-16" );
jsonMembers.put(member2);
json.put( "users" //以字符串形式返回JSON对象的内容
return json.toString();
}
//从字符串构造一个JSON对象并解析之
String jsonTest2() JSONException{
String jsonString= "{"users":[{"loginname":"jack","password":"userpass","email":"fbeiwb@163.com"},{"loginname":"tom","email":"1231231@163.com"}]}" ;
JSONObject json= JSONObject(jsonString);
JSONArray jsonArray=json.getJSONArray( );
String loginNames= "loginname list:" ;
for ( int i= 0 ;i<jsonArray.length();i++){
JSONObject user=(JSONObject) jsonArray.get(i);
String userName=(String) user.get( );
if (i==jsonArray.length()- 1 ){
loginNames+=userName;
} else {
loginNames+=userName+ "," ;
}
}
loginNames;
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读