• Android解析Json示范


     1 public class OneJsonActivity extends Activity {
     2 
     3     String JsonData = "[{"id":["386","381","379","377"],"num":["386","381","379","377"]},{"id":["3860","3810","3790","3770"],"num":["3860","3810","3790","3770"]}]";
     4     JSONObject obj = null;
     5     JSONArray jsonArary;
     6 
     7     @Override
     8     protected void onCreate(Bundle savedInstanceState) {
     9         super.onCreate(savedInstanceState);
    10         setContentView(R.layout.one_json_activity);
    11         
    12 
    13         try {
    14             jsonArary = new JSONArray(JsonData);
    15             for (int i = 0; i < jsonArary.length(); i++) {
    16                 obj = jsonArary.getJSONObject(i);
    17                 // 取ID
    18                 JSONArray strID = obj.getJSONArray("id");
    19                 for (int j = 0; j < strID.length(); j++) {
    20                     Log.v("ID:", strID.get(j).toString());
    21                 }
    22                 // 取num
    23                 JSONArray strNum = obj.getJSONArray("num");
    24                 for (int k = 0; k < strNum.length(); k++) {
    25                     Log.v("NUM:", strNum.get(k).toString());
    26                 }
    27                 
    28             }
    29         } catch (JSONException e) {
    30             e.printStackTrace();
    31         }
    32 
    33     }
    34 
    35 }

    JSON在线校验、格式化、视图( {} 对象 [] 数组 )

    http://www.bejson.com/jsonviewernew/

  • 相关阅读:
    Intersection(计算几何)
    Happy Matt Friends(DP)
    Dire Wolf(区间DP)
    Black And White(DFS+剪枝)
    最大子矩阵
    Largest Rectangle in a Histogram (最大子矩阵)
    City Game(最大子矩阵)
    Zipper (DP)
    QQpet exploratory park(DP)
    C++程序设计(第4版)读书笔记_指针、数组与引用
  • 原文地址:https://www.cnblogs.com/spadd/p/4424068.html
Copyright © 2020-2023  润新知