ios – 从对象到json

ios – 从对象到json,第1张

概述参见英文答案 > Convert an iOS objective c object to a JSON string                                    4个 如何在JSON中转换对象列表?我搜索了互联网,但我使用的所有方法都出错了.我需要将对象coll转换为字符串json Collections *current = _raccolte[_currentCel 参见英文答案 > Convert an iOS objective c object to a JSON string                                    4个
如何在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所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1046816.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-24
下一篇 2022-05-24

发表评论

登录后才能评论

评论列表(0条)

保存