android json

android

2013-05-25 16:59

 新建

    JSONObject j= new JSONObject();
     j.put("aaa", "female");
     j.put("bbb", "zhangsan");    


读取 


    js= new JSONObject(String);
    s=js.getString("aaa").toString();
    ss=js.getString("bbb").toString();
            



多维

<?php
$arr=array();


$arr[]=array("a"=>"1","b"=>"asd","c"=>"ass");
$arr[]=array("a"=>"2","b"=>"bbb","c"=>"asx");
$arr[]=array("a"=>"3","b"=>"ccc","c"=>"asf");
$arr[]=array("a"=>"4","b"=>"ddd","c"=>"as3");
$arr[]=array("a"=>"5","b"=>"fff","c"=>"asgf");
$arr[]=array("a"=>"6","b"=>"ggg","c"=>"as3");
$arr[]=array("a"=>"7","b"=>"hhh","c"=>"asg");



$json_string = json_encode($arr);  
echo $json_string; 

?>





解析

String jj="[{'a':'1','b':'asd','c':'ass'},{'a':'2','b':'bbb','c':'asx'},{'a':'3','b':'ccc','c':'asf'},{'a':'4','b':'ddd','c':'as3'},{'a':'5','b':'fff','c':'asgf'},{'a':'6','b':'ggg','c':'as3'},{'a':'7','b':'hhh','c':'asg'}]";

JSONArray jsonArray =new JSONArray(jj);
    int iSize = jsonArray.length();
    for (int i = 0; i < iSize; i++) {
    JSONObject jsonObj = jsonArray.getJSONObject(i);
    Log.v("json", "值"+jsonObj.get("a"));
    Log.v("json", "值"+jsonObj.get("b"));
    Log.v("json", "值"+jsonObj.get("c"));
    }