NSMutable array containing NSDictionary to server
I'm creating a small project where I want to post a NSMutableArray containing multiple NSDictionarys to a server. The thing is that the Array is dynamic. I don't know how many dicti开发者_开发技巧onaries it will contain. This is the layout of the Mutablearray:
(
{
Category = Music;
Description = "Detta \U00e4r mitt quiz!";
Difficulty = 1;
Language = Swedish;
Title = "Mitt Quiz";
},
{
QuestionNr1 = {
Question = "Vilken stad bor jag i?";
RightAnswer = Uppsala;
WrongAnswer1 = Stockholm;
WrongAnswer2 = "Ume\U00e5";
WrongAnswer3 = Visby;
};
QuestionNr2 = {
Question = "Vilken stad bor jag inte i?";
RightAnswer = Uppsala;
WrongAnswer1 = Stockholm;
WrongAnswer2 = "Ume\U00e5";
WrongAnswer3 = Visby;
};
}
)
I now want to post this to PHP/MYSQL-Server. I could do this by Splitting up the array to it's string components and concatenating a string to a URL containing all it's variables. But that wouldn't work if I'm not knowing how many Questions/Dictionarys the array will contain. Plus that it feels wrong building this LONG url for the request.
Is there any other way, using JSON for example that makes posting this structure to my php-server easy?
Thanks!
This is exactly what JSON was designed to do. See the documentation for NSJSONSerialization
.
精彩评论