来自 NSString 的 NSJSONSerialization [英] NSJSONSerialization from NSString

查看:22
本文介绍了来自 NSString 的 NSJSONSerialization的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个 NSString 并且我想使用 NSJSONSerialization,这可能吗?我该怎么做?

Is it possible if I have a NSString and I want to use NSJSONSerialization? How do I do this?

推荐答案

首先,您需要通过执行以下操作将 NSString 转换为 NSData

First you will need to convert your NSString to NSData by doing the following

NSData *data = [stringData dataUsingEncoding:NSUTF8StringEncoding];

然后只需使用 JSONObjectWithData 方法将其转换为 JSON

then simply use the JSONObjectWithData method to convert it to JSON

id json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];

这篇关于来自 NSString 的 NSJSONSerialization的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆