Android(安卓)Json数据解析
16lz
2021-01-26
package com.example.h3c.util;import java.util.ArrayList;import org.json.JSONArray;import org.json.JSONException;import org.json.JSONObject;import org.json.JSONTokener;import android.util.Log;import com.example.pickride.entity.PincheInfo;public class DataParser { // {”pincheinfolist”:[{“username”:”王五”},{“telephone”:“xxxxxx”},{“destination”:“xxxxx”},{“location”:“xxx”},{“time”:“xxx”}]} public static ArrayList<PincheInfo> PincheInfoParser(String jsonStr) { ArrayList<PincheInfo> pincheInfoArr = new ArrayList<PincheInfo>(); try { JSONTokener jsonParser = new JSONTokener(jsonStr); JSONObject person = (JSONObject) jsonParser.nextValue(); JSONArray jsonArr = person.getJSONArray("pincheinfolist"); int length = jsonArr.length(); for (int i = 0; i < length; i++) {// 遍历JSONArray JSONObject oj = jsonArr.getJSONObject(i); PincheInfo pi = new PincheInfo(); pi.username = oj.getString("username"); pi.telephone = oj.getString("telephone"); pi.destination = oj.getString("destination"); pi.location = oj.getString("location"); pi.time = oj.getString("time"); pincheInfoArr.add(pi); } } catch (JSONException e) { Log.d(ConstantsTable.LOG_TAG, "DataParser: pincheInfo json error!"); e.printStackTrace(); } return pincheInfoArr; }}
更多相关文章
- cocos2d-x 3.0 android mk文件 之 自动遍历*.cpp文件
- Android(安卓)解析strings.xml国际化
- android Q 使用 ACTION_OPEN_DOCUMENT_TREE 选择目录进行遍历文
- android+kotlin开发笔记(一)
- HashMap 的 7 种遍历方式与性能分析!「修正篇」
- HashMap 的 7 种遍历方式与性能分析!(强烈推荐)
- Android退出程序(二)——利用广播机制
- Android(安卓)GPS坐标 画路线
- Android联系人4--联系人查询