0

データ型 NSDictionary は JSON 構造に関連しており、助けが必要なため、少し混乱しています。これが私のJSON出力です:

{
    "requestDetails":
    {
        "timeStamp":"2001-12-17T09:30:47-08:00",
        "transactionType":"QUERY",
        "action":"GET INVOICES",
    },
    "Payload":
    {
        "event":
        {
            "sourceRecordType":"INVOICE INQUIRY",
            "serviceRecordType":"INVOICE",
            "ownershipType":"EXPLICIT",
        },
    },
    "executionDetails":
    {
        "timeStamp":"2012-12-04T13:48:21-08:00",
        "statusType":   "SUCCESSFUL_TRANSACTION",
        "statusCode":"0",
        "DBRecordCount":"0",
        "processedRecordCount":"0",
        "warning":
        [
            {
                "errorCode":"257",
                "errorDescription":"Criteria specified is incorrect. Please Verify that the criteria is correct.",
                "__hashCodeCalc":false
            },
            {   "errorCode":"60",
                "errorDescription":"No results were found.  Please enter new search criteria.",
                "__hashCodeCalc":false
            }
        ],
    },
}

今、私の理解では、これはすべて辞書であり、objectForKey:@"executionDetails" は次の出力を提供します。

{
        "timeStamp":"2012-12-04T13:48:21-08:00",
        "statusType":   "SUCCESSFUL_TRANSACTION",
        "statusCode":"0",
        "DBRecordCount":"0",
        "processedRecordCount":"0",
        "warning":
        [
            {
                "errorCode":"257",
                "errorDescription":"Criteria specified is incorrect. Please Verify that the criteria is correct.",
                "__hashCodeCalc":false
            },
            {   "errorCode":"60",
                "errorDescription":"No results were found.  Please enter new search criteria.",
                "__hashCodeCalc":false
            }
        ],
    }

[] 括弧内の値を選択するにはどうすればよいですか。valueForKey と ObjectForKey を試しました。処理構造がよくわからないので、助けていただければ幸いです

warning":
        [
            {
                "errorCode":"257",
                "errorDescription":"Criteria specified is incorrect. Please Verify that the criteria is correct.",
                "__hashCodeCalc":false
            },
            {   "errorCode":"60",
                "errorDescription":"No results were found.  Please enter new search criteria.",
                "__hashCodeCalc":false
            }
        ],

ありがとう

4

1 に答える 1

1

これは単なる配列です。このようにコンテンツにアクセスできます。

NSDictionary *executionDetails = [json objectForKey:@"executionDetails"];
NSArray *warnings = [executionDetails objectForKey:@"warning"];

for (NSDictionary *warning in warnings) {
    NSLog(@"%@", warning);
}
// To access an individual warning use: [warnings objectAtIndex:0]

より明確にするために、最新の Objective-C 構文を使用することもできます。

NSDictionary *executionDetails = json[@"executionDetails"];
NSArray *warnings = executionDetails[@"warning"];
NSLog(warnings[0]);
于 2012-12-04T23:06:37.463 に答える