【问题标题】:how to parse with double quotes array of dictionary into json in ios?如何在ios中将字典的双引号数组解析为json?
【发布时间】:2013-11-08 09:27:24
【问题描述】:

如何为数字添加双引号。当我解析时,对于没有双引号的数字。对于字符串,双引号会很好。我想要所有的双引号。下面是我的字典数组

我创建的这个字典数组

    (
    {
    questionId = 91;
    responseLanguage = ar;
    responseType = 4;
},
    {
    questionId = 92;
    responseLanguage = ar;
    responseType = 2;
}
)

我想这样解析

[{"questionId":"91","responseType":"4","responseLanguage":"ar"},  {"questionId":"92","responseType":"2","responseLanguage":"ar"}]

当我使用 sbjson 解析器只解析字符串时,它是双引号,对于数字,它不是双引号。

【问题讨论】:

    标签: ios json nsmutablearray nsdictionary sbjson


    【解决方案1】:
    (
      {
        questionId = @"91";
        responseLanguage = ar;
        responseType = @"4";
      },
      {
        questionId = @"92";
        responseLanguage = ar;
        responseType = @"2";
      }
    )
    

    这样就可以了,如果这个数组正在生成动态,那么在添加到字典时使用“stringValue”方法将数字转换为字符串

    NSDictionary *parameters = [NSDictionary dictionaryWithObjectsAndKeys:
                                    [nsnumber stringValue], @"questionId",
                                    ar, @"responseLanguage",
                                    [nsnumber stringValue], @"responseType", nil];
    

    【讨论】:

    • 在添加到字典之前我做了这个方法它工作 NSString *myString = [NSNumber stringValue];
    • 添加字典时可以直接使用[nsnumber stringValue],如果对你有帮助请采纳,谢谢
    【解决方案2】:

    在创建字典时将数字转换为字符串。双引号代表字符串。

    【讨论】:

    • 是的,我只是之前做过,没有来。
    猜你喜欢
    • 2018-09-05
    • 1970-01-01
    • 2021-11-11
    • 2018-09-26
    • 1970-01-01
    • 1970-01-01
    • 2017-11-18
    • 2012-07-19
    • 1970-01-01
    相关资源
    最近更新 更多