我希望从中得到价值。
字符串
“[{\” VisitorId \ “:\” dbd1c1d6-8348-4674-9e48-65137bdc5c14 \ “\ ”OperatorID \“:空,\ ”VisitorSignalId \“:\” 6c454fc2-cf74-4010-aecd- 93d93408ad24 \ “\ ”类型\“:\ ”观众\“,\ ”MessageText中\“:\” ksksksksksk 已加入聊天!\“,\”IsJoin \“:true,\”MessageTime \“:\”2017-02-07 五点十分28秒\ “\ ”文件\“:空,\ ”消息类型\“:\ ”JoinMessage \“,\ ”名称\“:\ ”ksksksksksk \“,\ ”电子邮件\“:\” skdsm @ fdg.com \“,\”IP \“:\”123.231.110.188 \“,\”Page \“:\”http://www.sathyabaman.com/ \“,\”评分\“:\”无评级\“,\ “图片\”:空,\ “CurrentOpImage \”:空,\ “FileUploadDetails \”:空,\ “FirstOperatorName \”:空,\ “OperatorCount \”:1,\ “RequestTranscript \”:虚假,\“国家\ “:空,\” OS \ “:空,\” Broswer \ “:空,\” 移动\ “:空,\” iso_code \ “:空},{\” VisitorId \ “:\” dbd1c1d6-8348 -4674-9e48-65137bdc5c14 \”,\ “OperatorID \”:空,\ “VisitorSignalId \”:空,\ “类型\”:\ “观众\”,\ “MessageText中\”:\ “lkkhnl \”,\ “IsJoin \”:虚假,\ “MessageTime \”:\“2017年2月7日 5时10分58秒\ “\ ”文件\“:空,\ ”消息类型\“:\ ”NormalMessage \“,\ ”名称\“:\ ”ksksksksksk \“,\ ”电子邮件\“:\” skdsm @ fdg.com \“,\”IP \“:\”123.231.110.188 \“,\”Page \“:\”http://www.sathyabaman.com/ \“,\”评分\“:\”无评级\“,\ “图片\”:空,\ “CurrentOpImage \”:空,\ “FileUploadDetails \”:空,\ “FirstOperatorName \”:空,\ “OperatorCount \”:1,\ “RequestTranscript \”:虚假,\“国家\ “:空,\” OS \ “:空,\” Broswer \ “:空,\” 移动\ “:空,\” iso_code \ “:空},{\” VisitorId \ “:空,\” OperatorID \ “:\” 81aebba9-ddc3-4f58-B1AF-ac912d23a41e \ “\ ”VisitorSignalId \“:空,\ ”类型\“:\ ”操作\“,\ ”MessageText中\“:\” 怎么样 我能帮你吗?\“,\”IsJoin \“:false,\”MessageTime \“:\”2017-02-07 10时41分11秒\ “\ ”文件\“:空,\ ”消息类型\“:\ ”NormalMessage \“,\ ”名称\“:\ ”沙迪亚\“,\ ”电子邮件\“:空,\” IP \ “:空,\” 页\ “:空,\” 评级\ “:空,\” 图片\ “:空,\” CurrentOpImage \ “:空,\” FileUploadDetails \ “:空,\” FirstOperatorName \ “:\” 沙迪亚\ “\ ”OperatorCount \“:1,\ ”RequestTranscript \“:空,\ ”国家\“:空,\ ”OS \“:空,\ ”Broswer \“:空,\”移动\ “:空,\” iso_code \ “:空},{\” VisitorId \ “:\” dbd1c1d6-8348-4674-9e48-65137bdc5c14 \”,\ “OperatorID \”:空,\ “VisitorSignalId \”: \ “6c454fc2-cf74-4010-AECD-93d93408ad24 \”,\ “类型\”:\ “观众\”,\ “MessageText中\”:\“访客 不再活跃\“,\”IsJoin \“:false,\”MessageTime \“:\”2017年2月7日 5时11分53秒 AM \ “\ ”文件\“:空,\ ”消息类型\“:\ ”TransferMessage \“,\ ”名称\“:\ ”ksksksksksk \“,\ ”电子邮件\“:\” skdsm@fdg.com \ “,”\“IP \”:\“123.231.110.188 \”,\“Page \”:\“http://www.sathyabaman.com/ \”,\“评分\”:\“无评级\”,\“图片\” :空,\ “CurrentOpImage \”:空,\ “FileUploadDetails \”:空,\ “FirstOperatorName \”:空,\ “OperatorCount \”:1,\ “RequestTranscript \”:虚假,\ “国家\”:空,\ “OS \”:空,\ “Broswer \”:空,\ “移动\”:空,\ “iso_code \”:空},{\ “VisitorId \”:空,\ “OperatorID \”:\ “81aebba9-ddc3-4f58-B1AF-ac912d23a41e \”,\ “VisitorSignalId \”:空,\ “类型\”:\ “操作\”,\ “MessageText中\”:\ “你好\”,\ “IsJoin \” :假的,\ “MessageTime \”:\“2017年2月7日 10时47分54秒\ “\ ”文件\“:空,\ ”消息类型\“:\ ”NormalMessage \“,\ ”名称\“:\ ”沙迪亚\“,\ ”电子邮件\“:空,\” IP \ “:空,\” 页\ “:空,\” 评级\ “:空,\” 图片\ “:空,\” CurrentOpImage \ “:空,\” FileUploadDetails \ “:空,\” FirstOperatorName \ “:\” 沙迪亚\ “\ ”OperatorCount \“:1,\ ”RequestTranscript \“:空,\ ”国家\“:空,\ ”OS \“:空,\ ”Broswer \“:空,\”移动\ “:空,\” iso_code \ “:空},{\” VisitorId \ “:空,\” OperatorID \ “:\” 81aebba9-ddc3-4f58-B1AF-ac912d23a41e \”,\ “VisitorSignalId \”:空,\ “类型\”:\ “操作\”,\ “MessageText中\”:\“怎么样 我能帮你吗?\“,\”IsJoin \“:false,\”MessageTime \“:\”2017-02-07 十时50分07秒\ “\ ”文件\“:空,\ ”消息类型\“:\ ”NormalMessage \“,\ ”名称\“:\ ”沙迪亚\“,\ ”电子邮件\“:空,\” IP \ “:空,\” 页\ “:空,\” 评级\ “:空,\” 图片\ “:空,\” CurrentOpImage \ “:空,\” FileUploadDetails \ “:空,\” FirstOperatorName \ “:\” 沙迪亚\ “\ ”OperatorCount \“:1,\ ”RequestTranscript \“:空,\ ”国家\“:空,\ ”OS \“:空,\ ”Broswer \“:空,\”移动\ “:空,\” iso_code \ “:空},{\” VisitorId \ “:空,\” OperatorID \ “:\” 81aebba9-ddc3-4f58-B1AF-ac912d23a41e \”,\ “VisitorSignalId \”:空,\ “类型\”:\ “操作\”,\ “MessageText中\”:\ “\”,\ “IsJoin \”:虚假,\ “MessageTime \”:\“2017年2月7日 10点57分13秒\ “\ ”文件\“:空,\ ”消息类型\“:\ ”NormalMessage \“,\ ”名称\“:\ ”沙迪亚\“,\ ”电子邮件\“:空,\” IP \ “:空,\” 页\ “:空,\” 评级\ “:空,\” 图片\ “:空,\” CurrentOpImage \ “:空,\” FileUploadDetails \ “:空,\” FirstOperatorName \ “:\” 沙迪亚\ “\ ”OperatorCount \“:1,\ ”RequestTranscript \“:空,\ ”国家\“:空,\ ”OS \“:空,\ ”Broswer \“:空,\”移动\ “:空,\” iso_code \ “:空}]”
方式
+ (void) showCurrentHistory:(NSString *) historyString {
NSString* processed = [historyString stringByReplacingOccurrencesOfString:@"\\\"" withString:@"\""];
NSString* withotExtras = [[processed substringFromIndex:1] substringToIndex:[processed length] - 2];
NSData *data = [[NSData alloc] initWithBytes:[withotExtras UTF8String] length:withotExtras.length];
NSError *error;
NSMutableArray* jsonArray = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error];
for (NSDictionary *dic in jsonArray) {
NSString *VisitorId = [dic objectForKey:@"VisitorId"];
NSString *VisitorSignalId = [dic objectForKey:@"VisitorSignalId"];
NSString *Type = [dic objectForKey:@"Type"];
NSString *Messagetext = [dic objectForKey:@"Messagetext"];
NSString *MessageType = [dic objectForKey:@"MessageType"];
NSString *MessageTime = [dic objectForKey:@"MessageTime"];
NSString *Image = [dic objectForKey:@"Image"];
NSString *FileUploadDetails = [dic objectForKey:@"FileUploadDetails"];
NSString *FirstOperatorName = [dic objectForKey:@"FirstOperatorName"];
NSString *Rating = [dic objectForKey:@"Rating"];
NSLog(@"----------------------- Current Chat History --------------------------------");
NSLog(@"VisitorId : %@" , VisitorId);
NSLog(@"VisitorSignalId : %@" , VisitorSignalId);
NSLog(@"Type : %@" , Type);
NSLog(@"Messagetext : %@" , Messagetext);
NSLog(@"MessageType : %@" , MessageType);
NSLog(@"MessageTime : %@" , MessageTime);
NSLog(@"Image : %@" , Image);
NSLog(@"FileUploadDetails : %@" , FileUploadDetails);
NSLog(@"FirstOperatorName : %@" , FirstOperatorName);
NSLog(@"Rating : %@" , Rating);
NSLog(@"------------------------------------------------------------------------------");
MessageItemObject *item = [[MessageItemObject alloc] init];
[item setVisitorId:VisitorId];
[item setVisitorSignalId:VisitorSignalId];
[item setType:Type];
[item setMessagetext:Messagetext];
[item setMessageType:MessageType];
[item setMessageTime:MessageTime];
[item setImage:Image];
[item setFileUploadDetails:FileUploadDetails];
[item setFirstOperatorName:FirstOperatorName];
[item setRating:Rating];
if (messagesList.count == 0) {
messagesList = [[NSMutableArray alloc] init];
[messagesList addObject:item];
NSMutableDictionary *dic = [NSMutableDictionary dictionary];
[dic setValue:@"Adding new chatting" forKey:@"Adding new Chatting"];
[[NSNotificationCenter defaultCenter]
postNotificationName:@"PassData"
object:nil
userInfo:dic];
} else {
[messagesList addObject:item];
NSMutableDictionary *dic = [NSMutableDictionary dictionary];
[dic setValue:@"Adding new chatting" forKey:@"Adding new Chatting"];
[[NSNotificationCenter defaultCenter]
postNotificationName:@"PassData"
object:nil
userInfo:dic];
}
}
}
如果没有表情符号,此方法可以正常工作,因为此sting只有一个\ emoji,NSJSONSerialization不起作用。有人可以帮我解决这个问题。
答案 0 :(得分:1)
问题是您正在对JSON字符串进行硬编码并对其进行更改,不要对您的INSERT INTO time_in(late,time_in)
VALUES ('$late,NOW())";
字符串进行任何更改,并直接将其转换为JSON
。
NSData
答案 1 :(得分:1)
试试这个。
将带有表情符号的字符串转换为带有unicode的字符串,如下所示
NSData *data = [strEmoji dataUsingEncoding:NSNonLossyASCIIStringEncoding];
NSString *unicodeString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
如果你想在某个地方展示表情符号,那么你可以转换回表情符号。
NSData *data = [unicodeString dataUsingEncoding:NSUTF8StringEncoding];
NSString *emojiString = [[NSString alloc] initWithData:data encoding:NSNonLossyASCIIStringEncoding];