如何添加数字的双引号。当我解析时,数字不会出现双引号。对于字符串,双引号恰好。我想要所有人的双倍报价。以下是我的字典数组

我创建了这个词典

    (
    {
    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解析器解析时,仅引号即可到达双引号,因为数字不是双引号。

有帮助吗?

解决方案

(
  {
    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];

其他提示

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top