如何访问数组多JSON文件? [英] how to access multi array json file?
本文介绍了如何访问数组多JSON文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是低于我如何接取这个JSON文件检查我的方法是coreect方法尖子JSON文件阵列和节点我的code?我想接取从我的code低于这个JSON文件帮助我我怎么接取这个JSON文件formmy code?我dontknow的howmany阵列中的JSON文件
{
状态:1,
信息:,
数据:
{
学校:
[
{
ID:3,
名:FG公立学校
},
{
ID:4,
名:Fazaia国际学院}
]
}
}
HttpClient的客户端=新DefaultHttpClient();HttpConnectionParams.setConnectionTimeout(client.getParams(),15000);HttpConnectionParams.setSoTimeout(client.getParams(),15000);
HttpUriRequest要求=新HTTPGET(SelectMenuAPI);
HTT presponse响应= client.execute(请求);
InputStream的atomInputStream =
。response.getEntity()的getContent();
在的BufferedReader =新的BufferedReader(新
InputStreamReader的(atomInputStream));串线;
字符串str =;
而((行= in.readLine())!= NULL){
STR + =行;
}
JSONObject的JSON =新的JSONObject(STR);
JSONArray数据= json.getJSONArray(学校);的for(int i = 0; I< data.length();我++){
的JSONObject对象=
data.getJSONObject(ⅰ); //类的JSONObject =
object.getJSONObject(类别);
Category_ID.add(的Long.parseLong(object.getString(ID))); Category_name.add(object.getString(名字)); Log.d(类别名称,
Category_name.get(ⅰ));
解决方案
该类别的对象不是JSON文件内present
您可以尝试以下
JSONObject的JSON =新的JSONObject(STR);
JSONObject的数据= json.getJSONObject(数据);
JSONArray学校= json.getJSONArray(学校); 的for(int i = 0; I< data.length();我++){
的JSONObject对象= school.getJSONObject(I) 长ID =的Long.parseLong(object.getString(ID));
字符串名称= object.getString(名称);
JSONObject的类别=新的JSONObject();
category.put(ID);
category.put(名称);
}
this is my code below how do i acess this json file check my method it is coreect method to aces json file array and nodes? i want to acess this json file below from my code help me how do i acess this json file formmy code? i dontknow howmany array in json file
{
"status":1,
"message":"",
"data":
{
"school":
[
{
"id":3,
"name":"FG Public School"
},
{
"id":4,
"name":"Fazaia Inter College"}
]
}
}
HttpClient client = new DefaultHttpClient();
HttpConnectionParams.setConnectionTimeout(client.getParams(), 15000);
HttpConnectionParams.setSoTimeout(client.getParams(), 15000);
HttpUriRequest request = new HttpGet(SelectMenuAPI);
HttpResponse response = client.execute(request);
InputStream atomInputStream =
response.getEntity().getContent();
BufferedReader in = new BufferedReader(new
InputStreamReader(atomInputStream));
String line;
String str = "";
while ((line = in.readLine()) != null){
str += line;
}
JSONObject json = new JSONObject(str);
JSONArray data = json.getJSONArray("school");
for (int i = 0; i < data.length(); i++) {
JSONObject object =
data.getJSONObject(i);
// JSONObject category =
object.getJSONObject("Category");
Category_ID.add(Long.parseLong(object.getString("id")));
Category_name.add(object.getString("name"));
Log.d("Category name",
Category_name.get(i));
解决方案
The Category object is not present inside the Json file
you can try following
JSONObject json = new JSONObject("str");
JSONObject data = json.getJSONObject("data");
JSONArray school = json.getJSONArray("school");
for (int i = 0; i < data.length(); i++) {
JSONObject object = school.getJSONObject(i);
long id = Long.parseLong(object.getString("id"));
String name = object.getString("name");
JSONObject category = new JSONObject();
category.put("id");
category.put("name");
}
这篇关于如何访问数组多JSON文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文