search

Home  >  Q&A  >  body text

ios - AFN返回的数据中其中一个是数组,如何取到数组中的值?

通过AFN获取的返回值responseObject 如下:

{
    COCAudit = 1;
    COCHeadPicture = "COCHeadPicture13.jpg";
    COCId = 2;
    COCLevel = 11;
    COCPlateNumber = "\U9c81ayyuhg";
    COCTailPicture = "COCTailPicture13.jpg";
    COCXSZPicture = "COCXSZPicture13.jpg";
    COId = 13;
    carGIS =     (
                {
            CGId = 2;
            CGZF = 0;
            COMMCODE = 15150001;
            resultSign = true;
        }
    );
    resultSign = true;
}

求问如何取 carGIS 数组 中的 CGZF 的值?

高洛峰高洛峰2887 days ago363

reply all(4)I'll reply

  • 伊谢尔伦

    伊谢尔伦2017-04-17 17:43:27

    First, you need to learn the structure of JSON data. It has been briefly explained on the first floor.
    Secondly, when parsing JSON, the value of the key is a string, which is received using NSString, an array using NSArray, and a dictionary using NSDictionary.
    If value is an array or dictionary, you need to perform another value operation until you get the string position.

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-17 17:43:27

    You'd better learn about json, including how to write a json data.
    The corresponding key=value format in json
    carGIS corresponds to an array array
    array is an map(dictionary)

    reply
    0
  • 黄舟

    黄舟2017-04-17 17:43:27

    First of all, all the data returned is an NSDictionary object, in which carGIS is an array, and NSArray is used to receive and save it. Each element in the array is an NSDictionary object, which can be retrieved using the key value. In this question, the key value is CGZF.
    The following code is just a processing step for reference only:

     carGIS = responseObject[@"carGIS"];   //取出数组
     for (NSDictionary *dic in carGIS ) {
        CGId = dic[@"CGId"];
     }

    reply
    0
  • 迷茫

    迷茫2017-04-17 17:43:27

    You can try RestKit

    reply
    0
  • Cancelreply