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


更多相关文章

  1. cocos2d-x 3.0 android mk文件 之 自动遍历*.cpp文件
  2. Android(安卓)解析strings.xml国际化
  3. android Q 使用 ACTION_OPEN_DOCUMENT_TREE 选择目录进行遍历文
  4. android+kotlin开发笔记(一)
  5. HashMap 的 7 种遍历方式与性能分析!「修正篇」
  6. HashMap 的 7 种遍历方式与性能分析!(强烈推荐)
  7. Android退出程序(二)——利用广播机制
  8. Android(安卓)GPS坐标 画路线
  9. Android联系人4--联系人查询

随机推荐

  1. [置顶] 解决android某些应用开发某些类无
  2. Android(安卓)App集成支付宝
  3. 在 Ubuntu 下使用 Android(安卓)NDK r4b
  4. 3. 编写的第一个android HelloWorld程序
  5. 【Android个人理解(一)】通过Looper与Handl
  6. Android面试真题,了解一下?
  7. android缓存设计
  8. Gradle Android最新自动化编译脚本教程(
  9. 【设计模式与Android】单例模式——独一
  10. Android中点击空白区域控件自动隐藏(事件