Question

How to add double quotes for numbers. When I am parsing, for numbers not coming double quotes. For strings double quotes are coming fine. I want double quotes for all. Below is my array of dictionary

This array of dictionary I was created

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

I want to parse like this

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

when am parsing using sbjson parser only strings it was coming double quotes, for numbers it was not coming double quotes.

Was it helpful?

Solution

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

This will do and if this array is generating dynamic then convert number into string using "stringValue" method when to add into dictionary

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

OTHER TIPS

While creating dictionary convert the numbers to strings. Double quotes represents the strings.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top