如何在JsON中转换对象列表?我搜索了互联网,但我使用的所有方法都出错了.我需要将对象coll转换为字符串Json
Collections *current = _raccolte[_currentCell];current.label = [[alertVIEw textFIEldAtIndex:0] text];current.datetime_last_update = [NSNumber numberWithDouble:[[NSDate date] timeIntervalSince1970]];NSMutableArray *coll = [[NSMutableArray alloc] init];[coll addobject:current];httpClIEnt *clIEnt = [[httpClIEnt alloc] init];[clIEnt syncCollection:coll];解决方法 您使用NSJsONSerialization类将JsON转换为Foundation对象并将Foundation对象转换为JsON.
在这里你可以检查它Link
Collections *current = _raccolte[_currentCell];current.label = [[alertVIEw textFIEldAtIndex:0] text];current.datetime_last_update = [NSNumber numberWithDouble:[[NSDate date] timeIntervalSince1970]];NSMutableArray *coll = [[NSMutableArray alloc] init];[coll addobject:current.label];[coll addobject:current.datetime_last_update];NSError *writeError = nil; NSData *JsonData = [NSJsONSerialization dataWithJsONObject:coll options:NSJsONWritingPrettyPrinted error:&writeError];Nsstring *JsonString = [[Nsstring alloc] initWithData:JsonData enCoding:NSUTF8StringEnCoding]; NSLog(@"JsON Output: %@",JsonString);总结
以上是内存溢出为你收集整理的ios – 从对象到json全部内容,希望文章能够帮你解决ios – 从对象到json所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)