android 解析json資料格式

2021-09-01 07:35:27 字數 1780 閱讀 9206

json資料格式解析我自己分為兩種;

一種是普通的,一種是帶有陣列形式的;

普通形式的:

伺服器端返回的json資料格式如下:

}分析**如下:

// todo 狀態處理 500 200 

分析**如下:

// todo 狀態處理 500 200 

* 當返回碼為200時,做處理 

* 得到伺服器端返回json資料,並做處理 

* 這裡需要分析伺服器回傳的json格式資料, 

jsonobject jsonobject = new jsonobject(builder.tostring()) 

.getjsonobject("calendar"); 

jsonarray jsonarray = jsonobject.getjsonarray("calendarlist"); 

for(int i=0;ijsonobject jsonobject2 = (jsonobject)jsonarray.opt(i); 

calendarinfo calendarinfo = new calendarinfo(); 

calendarinfo.setcalendar_id(jsonobject2.getstring("calendar_id")); 

calendarinfo.settitle(jsonobject2.getstring("title")); 

calendarinfo.setcategory_name(jsonobject2.getstring("category_name")); 

calendarinfo.setshowtime(jsonobject2.getstring("showtime")); 

calendarinfo.setendtime(jsonobject2.getstring("endshowtime")); 

calendarinfo.setallday(jsonobject2.getboolean("allday")); 

calendarinfos.add(calendarinfo); 

總結,普通形式的只需用jsonobject ,帶陣列形式的需要使用jsonarray 將其變成乙個list。

Android 解析json資料

package com.practice.json import org.json.jsonarray import org.json.jsonexception import org.json.jsonobject import android.os.bundle import android.u...

android中的json解析

json和xml的解析有一些類似,將json的內容讀入字串之後 在進行解析 json資料是 包裹的是jsonobject,物件裡面是鍵值對,直接呼叫getstring 等等就可以 包裹的是jsonarray private void parsejsonwithjsonobject string js...

Android開發之json解析

現在分析下把我難倒了好幾天的乙個bug,就是json的解析。用到的api 獲得的json 1 16 query good 17 errorcode 0,18 web 19,27,3543 44 通過觀察json發現,既有大括號,又有中括號。1 payload 2 payload q content ...