【发布时间】:2021-08-08 09:48:00
【问题描述】:
我正在使用 websocket 来调用接收、接受和所有。接听电话时,我收到了 websocket 事件。
websocket 接受事件输出:-
{
action = signal;
"call_id" = 60a4d5b4850b3875f95dbc6e;
event = CALL;
from = 5b30ec0fa4cef4609038470b;
id = "330A1A48-A6BA-4B29-A4A2-9D9FDB85144D";
signal = {
offer = "RTC_OBJC_TYPE(RTCIceCandidate):\naudio\n0\ncandidate:1211696075 1 udp 41885439 3.8.66.208 62545 typ relay raddr 0.0.0.0 rport 0 generation 0 ufrag DT/j network-id 1 network-cost 10\nturn:3.8.66.208:3478?transport=udp";
};
to = 5b4854724f82e91934c1c475;
}
我正在使用下面的代码将上面的字典对象转换为 json 字符串。
-(NSString *)convertDictionaryToJsonString:(NSMutableDictionary *)dict {
NSError *error;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:&error];
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
return jsonString;
}
问题:- 应用程序崩溃了,原因是 - 'Invalid type in JSON write (RTCIceCandidate)'
谁能知道如何避免崩溃并解决这个问题?
谢谢。
【问题讨论】:
-
您的字典看起来还不错。你能告诉更多关于
dict的信息(有一个RTCIceCandidate对象吗?)dict[@"signal"][@"offer]真的是NSString还是自定义描述? -
(RTCIceCandidate) - 它在“offer”键值中,但整个内容是一个字符串。所以它可以工作。
-
@Larme 我编辑了问题,并完整回复了
dict -
该代码是否在您的 pod github.com/WebKit/WebKit/blob/… 中?否则,您能否检查每个属性的类型:
NSLog(@"Class: %@", NSStringFromClass([dict[@"signal"][@"offer] class]));。我猜它正在返回RTCIceCandidate,因为那是它的description:github.com/WebKit/WebKit/blob/… -
好吧,让我把日志和检查
标签: ios json objective-c dictionary websocket