zoukankan      html  css  js  c++  java
  • JSONArray和JSONObject

    1.JSONArray和JSONObject是什么

      JSONObject 就是{x:x , x:x , ...}这样的结构

      JSONArray 是元素是JSONOject的数组,就是[ {x:x , x:x , ...} , {x:x , x:x , ...} , ... ...]这样的结构

    2.字符串转JSONArray和JSONObejct的互相转化

      1)字符串转JSONObejct

        JSONObject Jobj =JSONObject.parseObject(String str)

      2)字符串转JSONArray

        JSONArray Jarr =JSONArray.parseArray(String str)

    3.获取JSONObejct内的数据

      ·keyset   得到key的集

      ·getString(key) 得到key对应的value

    4.遍历

           //假设  str ==  {"total":8109 , "rows":"[{ ...},{ ...},{ ...}]"}
         JSONObject jsonObject = JSONObject.parseObject(Str); JSONArray jsonArray = (JSONArray) jsonObject.get(Key); JSONObject tempJSon; for (Object obj : jsonArray) { tempJSon = (JSONObject) obj; for (String str : tempJSon.keySet()) { //key == str //value == tempJSon.getString(str) pass } }

    备注:

    用的包都是fastjson

    import com.alibaba.fastjson.JSON;
    import com.alibaba.fastjson.JSONArray;
    import com.alibaba.fastjson.JSONObject;
  • 相关阅读:
    1004 Counting Leaves
    1003 Emergency (25分)
    1002 A+B for Polynomials (25分)
    1001 A+B Format
    Weekly Contest 139
    491. Increasing Subsequences
    488. Zuma Game
    servlet总结
    firefox插件Firebug的使用教程
    KMP---POJ 3461 Oulipo
  • 原文地址:https://www.cnblogs.com/yejiang/p/10537508.html
Copyright © 2011-2022 走看看