Ⅰ 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;