1

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.

user2694118
  • 85
  • 1
  • 3
  • 10

2 Answers2

1
(
  {
    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];
Retro
  • 3,985
  • 2
  • 17
  • 41
  • Before adding into dictionary I did this method it working NSString *myString = [NSNumber stringValue]; – user2694118 Nov 08 '13 at 15:42
  • You can directly use when you adding the dictionary like [nsnumber stringValue], and please accept this answer if it helps you, thanks – Retro Nov 09 '13 at 10:02
0

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

Praveen Matanam
  • 2,773
  • 1
  • 20
  • 24