Ⅰ php如何獲取json中數據
可以用$obj=>key 的方式直接讀取 也可以先轉換為數組 用遍歷數組的方法讀取內
<?php
$json='{"a":100,"b":200,"c":300,"d":400,"e":500}';
//首先將json字元串容轉換成關聯數組
$arr=json_decode($json,true);
//然後循環讀取數據
foreach($arras$item){
echo$item;
echo"<br/>";
}
?>
運行結果:
100
200
300
400
500
Ⅱ Map類型獲取json數組,如何提取值
我們需要先把json字元串轉化為net.sf.json.JSONObject對象,java中這樣就可以完成json字元串到Map的轉換了。
1.將數組轉換為JSON:String[] arr = {"asd","dfgd","asd","234"};JSONArray jsonarray = JSONArray.fromObject(arr);System.out.println(jsonarray);
Ⅲ 如何java解析json數組
packagejava_email.demo;
importcom.google.gson.JsonArray;
importcom.google.gson.JsonObject;
importcom.google.gson.JsonParser;
publicclassReadJSON{
publicstaticvoidmain(Stringargs[]){
JsonParserparser=newJsonParser();//創建JSON解析器
Stringjson="{"title":"創建語音","content":[{"labels":["很好看","很好吃"],"voiceUrl":"/voice/1323423.pcm","voiceText":"很好","createDate":"2018-06-1114:29:43"},{"labels":["很好看1","很好吃"],"voiceUrl":"/voice/1323423.pcm","voiceText":"很好","createDate":"2018-07-2614:30:43"}],"enterpriseId":"20180726"}";
JsonObjectobject=(JsonObject)parser.parse(json);//創建JsonObject對象
System.out.println("title="+object.get("title"));//
System.out.println("enterpriseId="+object.get("enterpriseId"));
JsonArrayarray=object.get("content").getAsJsonArray();//得到為json的數組
System.out.println("content="+array);
for(inti=0;i<array.size();i++){
JsonObjectsubObject=array.get(i).getAsJsonObject();
System.out.println("labels="+subObject.get("labels"));
System.out.println("createDate="+subObject.get("createDate"));
}
}
}
Ⅳ js怎樣讀取json裡面的數據
varjson={contry:{area:{man:"12萬",women:"10萬"}}};
//方式一:使用eval解析
varobj=eval(json);
alert(obj.constructor);
alert(obj.contry.area.women);
//方式二:使用Funtion函數
varstrJSON="{name:'jsonname'}";//得到的JSON
varobj=newFunction("return"+strJSON)();//轉換後的JSON對象
alert(obj.name);//jsonname
alert(obj.constructor);
//復雜一點的json數組數據的解析
varvalue1=[{"c01":"1","c02":"2","c03":"3","c04":"4","c05":"5","c06":"6","c07":"7","c08":"8","c09":"9"},{"c01":"2","c02":"4","c03":"5","c04":"2","c05":"8","c06":"11","c07":"21","c08":"1","c09":"12"},{"c01":"5","c02":"1","c03":"4","c04":"11","c05":"9","c06":"8","c07":"1","c08":"8","c09":"2"}];varobj1=eval(value1);
alert(obj1[0].c01);
//復雜一點的json的另一種形式
varvalue2={"list":[{"password":"1230","username":"coolcooldool"},{"password":"thisis2","username":"okokok"}],"array":[{"password":"1230","username":"coolcooldool"},{"password":"thisis2","username":"okokok"}]};
varobj2=eval(value2);
alert(obj2.list[0].password);
Ⅳ jquery怎麼獲取json裡面的數組元素中每一個值
給的date是個json字元串,可以先轉成js對象:
let date_obj=JSON.parse(date);
此後date_obj就是一個對象,取到這個數組:
let arr=date_obj.numbers;
然後回用索答引訪問arr就能取到任意一個元素。
綜合為
JSON.parse(date).numbers[x],x為想取的元素索引,從0開始
Ⅵ python中如何遍歷json數組
1、創建python文件,testjson.py;