我从socketio服务器得到响应,我不知道如何解析它。我从socketio服务器收到一个包含事件的事件。
以下是按元素和跟踪语句细分的数据包:
po packet => <SocketIOPacket: 0x2561a1a0>
po packet.args => <__NSArrayI 0x256093e0>(
{"thing_id":"519192832f9053000001","bearing":0,"mph":0,"lng":-75.14617,"on_call":true,"lat":39.98132314,"name":"BJLKD"}
)
po packet.args[0] => $2 = 0x25606f60 {"thing_id":"519192832f9053000001","bearing":0,"mph":0,"lng":-75.14617,"on_call":true,"lat":39.98132314,"name":"BJLKD"}
我正在尝试访问这些元素,我尝试将其转换为NSArray,NSDictionary,保持原样并尝试访问它,如果它是NSArray和NSDicitionary并且没有任何作用。只有选择器错误。
任何人都有线索吗?
答案 0 :(得分:0)
解决方案是:
NSDictionary *JSON =
[NSJSONSerialization JSONObjectWithData: [packet.args[0] dataUsingEncoding:NSUTF8StringEncoding]
options: NSJSONReadingMutableContainers
error: &jsonParsingError];