Send NSMutableArray as JSON using JSON-Framework

后端 未结 3 1629
无人共我
无人共我 2021-01-19 14:08

I\'m using JSON-Framework in my project successfully to decode JSON send from a server.

Now I need to do it the other way around and I\'m facing problems as the data

3条回答
  •  南笙
    南笙 (楼主)
    2021-01-19 14:31

    I finally solved it, but I'm not sure if it's the best/most elegant way to do it.

    NSMutableArray* items = [[NSMutableArray alloc] init];
    for (MenuItems* item in menuItems) {
        [items addObject:[NSArray arrayWithObjects:item.id,[item.modified description],nil]];
    }
    NSString *post = [NSString stringWithFormat:@"currentData=%@",
                      [items JSONRepresentation]];
    

    Explanation:
    I first thought that the problem was the NSMutableArray, but then realized that it was the contents of it. So I just get the information I need out of it and saved it as NSArray which JSON-Framework does accept :-)

提交回复
热议问题