Search code examples
iosjsonnsmutablearraynsdictionarysbjson

how to parse with double quotes array of dictionary into json in ios?


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.


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