1. <tt id="5hhch"><source id="5hhch"></source></tt>
    1. <xmp id="5hhch"></xmp>

  2. <xmp id="5hhch"><rt id="5hhch"></rt></xmp>

    <rp id="5hhch"></rp>
        <dfn id="5hhch"></dfn>

      1. Json的生成與解析

        時間:2020-11-09 17:28:17 JSON 我要投稿

        Json的生成與解析

          JSON常用與服務器進行數據交互,JSON中“{}”表示JSONObject,“[]”表示JSONArray

          如下json數據:

          1 {"singers":[2 {"id":"02","name":"tom","gender":"男","tel":["123456","789012"]},3 {"id":"03","name":"jerry","gender":"男","tel":["899999","666666"]},4 {"id":"04","name":"jim","gender":"男","tel":["7777","5555"]},{"id":"05","name":"lily","gender":"女","tel":["222222","111111"]}5 ]}

          生成json數據代碼:

          public String buildJson() throws JSONException { JSONObject persons = new JSONObject(); JSONArray personArr = new JSONArray(); JSONObject person = new JSONObject(); person.put("id", "02"); person.put("name", "tom"); person.put("gender", "男"); JSONArray tel = new JSONArray(); tel.put("123456"); tel.put("789012"); person.put("tel", tel); personArr.put(person); JSONObject person2 = new JSONObject(); person2.put("id", "03"); person2.put("name", "jerry"); person2.put("gender", "男"); JSONArray tel2 = new JSONArray(); tel2.put("899999"); tel2.put("666666"); person2.put("tel", tel2); personArr.put(person2); JSONObject person3 = new JSONObject(); person3.put("id", "04"); person3.put("name", "jim"); person3.put("gender", "男"); JSONArray tel3 = new JSONArray(); tel3.put("7777"); tel3.put("5555"); person3.put("tel", tel3); personArr.put(person3); JSONObject person4 = new JSONObject(); person4.put("id", "05"); person4.put("name", "lily"); person4.put("gender", "女"); JSONArray tel4 = new JSONArray(); tel4.put("222222"); tel4.put("111111"); person4.put("tel", tel4); personArr.put(person4); persons.put("singers", personArr); return persons.toString(); }

          解析json數據代碼:

          private void parseJsonMulti(String strResult) { try { JSONArray jsonObjs = new JSONObject(strResult).getJSONArray("singers"); String s = ""; for (int i = 0; i < jsonObjs.length(); i++) { JSONObject jsonObj = ((JSONObject) jsonObjs.opt(i)); int id = jsonObj.getInt("id"); String name = jsonObj.getString("name"); String gender = jsonObj.getString("gender"); s += "ID號" + id + ", 姓名:" + name + ",性別:" + gender + ",電話:"; JSONArray tel = jsonObj.getJSONArray("tel"); for (int j = 0; j < tel.length(); j++) { s += tel.getString(j)+"/"; } s += "n"; } tv.setText(s); } catch (JSONException e) { e.printStackTrace(); } }

        【Json的生成與解析】相關文章:

        1.json實例解析方法

        2.IOS中Json解析實例方法詳解

        3.Json對象與Json字符串4種轉換方式

        4.jQuery解析json數據實例分析問題

        5.JSON與XML的區別及案例應用

        6.jquery與json的結合的知識點講解

        7.java與javascript之間json格式數據互轉詳解

        8.JSON數組用法介紹

        国产高潮无套免费视频_久久九九兔免费精品6_99精品热6080YY久久_国产91久久久久久无码

        1. <tt id="5hhch"><source id="5hhch"></source></tt>
          1. <xmp id="5hhch"></xmp>

        2. <xmp id="5hhch"><rt id="5hhch"></rt></xmp>

          <rp id="5hhch"></rp>
              <dfn id="5hhch"></dfn>