Parsing json with android

后端 未结 4 2028
日久生厌
日久生厌 2021-01-28 09:44

Hi I want to parse this json:

[{
    \"codError\": 0,
    \"msg\": \"OK\"
}, {
    \"id\": 1,
    \"role\": {
        \"id\": 4,
        \"name\": \"Super\",
            


        
4条回答
  •  南笙
    南笙 (楼主)
    2021-01-28 10:21

    First of all, the U4 doesn't seems JSON correct. I would have write it like:

    {
      "your array":["U4"]
    }
    

    then use the method to get your array

    JSONArray array = jsonObj.getJSONArray("your array");
    

    then you can access the values on your JSONArray by iterating over it, like that

    for (int i = 0; i < array.length(); i++) {
      array.getJSONObject(i);
    }
    

    Hope I help

提交回复
热议问题