gpt4 book ai didi

ios - 如何在解析 xml 时访问 NSDictionary 内的 NSArray?

转载 作者:行者123 更新时间:2023-11-29 02:43:07 24 4
gpt4 key购买 nike

我正在使用 XMLReader 来解析 xml 响应。我已将 xml 转换为 NSDictionary。现在我想访问 NSDictionary 中名为“cTrx”的数组。这是我的 NSDictionary:

{
Envelope = {
Body = {
fRetrieveTransactionsforReversalResponse = {
fRetrieveTransactionsforReversalResult = {
pCellularNumber = {
text = 0825669995;
};
pResponseCode = {
text = 00;
};
pResponseMessage = {
text = Approved;
};
pTrx = {
cTrx = (
{
pCardHolderName = {
};
pReference = {
text = 140826121114;
};
pTransactionAccount = {
text = "364241****0016";
};
pTransactionDate = {
text = "8/26/2014 12:11:18 PM";
};
pTransactionID = {
text = 23;
};
},
{
"xsi:nil" = true;
}
);
};
};
};
};
};
}

谢谢。

最佳答案

您可以使用方括号访问字典和数组值:

val = dictionary[@"key"];
item = array[i];

它也适用于嵌套字典:

NSDictionary *nested = @{@"dict_key": dictionary};
dictionaryVal = nexted[@"dict_key"][@"key"];

因此,在您的情况下,您可以通过以下方式访问 cTrx 数组:

NSArray *cTrx = yourDictionary[@"Envelope"][@"Body"][@"fRetrieveTransactionsforReversalResponse"][@"pTrx"][@"cTrx"];

长串代码:)

关于ios - 如何在解析 xml 时访问 NSDictionary 内的 NSArray?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25503972/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com