2017-02-07 5 views
0

이 값을 얻고 싶습니다.NSJSONSerialization이 그림 이모티콘으로 작동하지 않습니다.

문자열

"[{\"VisitorId \ "\"dbd1c1d6-8348-4674-9e48-65137bdc5c14 \ ", \"OperatorID \ "널 (null), \"VisitorSignalId \ " \ "Messagetext \": \ "ksksksksksk 님이 채팅에 참여했습니다! \", \ "IsJoin \": \ "6c454fc2-cf74-4010-aecd-93d93408ad24 \ true, \ "MessageTime \": \ "2017-02-07 05:10:28 \", \ "File \": null, \ "MessageType \": \ "JoinMessage \", \ "Name \": \ "IP \", \ "IP \": \ "123.231.110.188 \", \ "Page \": \ "http://www.sathyabaman.com/ \", \ "ksksksksksk \ \ "CurrentOpImage \": null, \ "FileUploadDetails \": null, \ "FirstOperatorName \": null, \ "OperatorCo "Broswer": null, \ "Mobile \": null, \ "iso_code \": null, \ " ": null, \"VisitorId \ ": \"db \ d1c1d6-8348-4674-9e48-65137bdc5c14 \ ", \"OperatorID \ ": null, \"VisitorSignalId \ ": null, \"유형 \ ": \" MessageTime \ ": \"2017-02-07 05:10:58 \ ", \"메시지 \ ", \"메시지 \ ", \" ": null,"MessageType ": \"NormalMessage \ ", \"Name \ ": \"ksksksksksk \ ", \"Email \ ": \"[email protected] \ ", \"IP \ " \ "Image \": null, \ "CurrentOpImage \": null, \ "123.231.110.188 \", \ "Page \": \ "http://www.sathyabaman.com/ \ "FileUploadDetails \": null, \ "FirstOperatorName \": null, \ "OperatorCount \": 1, \ "RequestTranscript \": false, \ "Country \": null, \ "OS \": null, \ "Broswer \ "모바일 \": null, \ "iso_code \": null}, {\ "VisitorId \": null, \ "OperatorID \": \ "81aebba9-ddc3-4f58-b1af-ac912d23a41e \": \ "유형 \", \ "운영자 \", \ "메시지 문자 \": \ "VisitorSignalId \"는 오늘 어떻게 도와 드릴까요? \ ", \"IsJoin \ ": false, \" 메시지 \ "Message \": null, \ "MessageType \": \ "NormalMessage \", \ "Name \": \ "sathya \": \ "2017-02-07 10:41:11 \ \ "Image \": null, \ "CurrentOpImage \": null, \ "IP \": null, \ " \ "FileUploadDetails \": null, \ "FirstOperatorName \": \ "sathya \", \ "OperatorCount \": 1, \ "RequestTranscript \": null, \ "Country \": null, \ "OS \": null, \ "Broswer \": null, \ "모바일 \": null, \ "iso_code \": null}, \ "VisitorId \": \ "dbd1c1d6-8348-4674-9e48-65137bdc5c14 \ \ "VisitorSignal \": \ "VisitorSignalId \": \ "6c454fc2-cf74-4010-aecd-93d93408ad24 \", \ "유형 \": \ "방문자 \", \ "Messagetext \": \ "방문자는 입니다. 2047 년 2 월 7 일 5:11:53 AM \ ", \"파일 \ ": null, \"MessageType \ ", 더 긴 활성", \ "IsJoin \": \ "IP 주소": \ "123.231.110.188 \", \ "IP 주소 : \" "페이지 \": \ "http://www.sathyabaman.com/ \", \ "등급 \": \ "등급 없음 \", \ "이미지 \": null, \ "CurrentOpIm \ "FileUploadDetails \": null, \ "FirstOperatorName \": null, \ "OperatorCount \": 1, \ "RequestTranscript \": false, \ "Country \": null, \ "OS \ "null : \"Broswer \ ": null, \"모바일 \ ": null, \"iso_code \ ": null}, \"VisitorId \ ": null, \"OperatorID \ ": \"81aebba9-ddc3- "방문객 신호": null, \ "유형 \": \ "운영자 \", \ "메시지 문자 \ : \"안녕하세요 \ ", \"이진 \ ": 거짓, \" \ "Message \": \ "MessageType \": \ "NormalMessage \", \ "Name \": \ "s \"MessageTime \ ": \"2017-02-07 10:47:54 " \ "Image \": null, \ "CurrentOpImage \": null, \ "IP \": null, \ " \ "FileUploadDetails \": null, \ "FirstOperatorName \": \ "sathya \", \ "OperatorCount \": 1, \ "RequestTranscript \": null, \ "Country \": null, \ "OS \": null, \ "이동자 \": null, \ "iso_code \": null}, \ "방문자 ID :": null, \ "운영자 ID \": \ "81 \ uc2b9c \ ddc3-4f58- \ "유형 \": \ "운영자 \", \ "메시지 문자 \": \ "어떻게 \\\\\\\\\ 방문객 신호 \\\\\\\\\\\\\\\\\\\\\\ "MessageType \": \ "MessageType \": \ "2017-02-07 10:50:07 \", \ "File \": null, \ "MessageType \": \ "Normal \" \ "IP \": null, \ "페이지 \": null, \ "등급 \": null, \ "이미지 \", \ "이름 \": \ "sathya \", \ "FileOploadDetails \": null, \ "FirstOperatorName \": \ "sathya \", \ "OperatorCount \": 1, \ "RequestTranscript \": null, \ "CurrentOpImage \ \ "모바일 \": null, \ "iso_code \": null}, {\ "VisitorId \": null, \ "Broswer \": null, \ "OS \ \ "유형 \": \ "운영자 \", \ "메시지 구문 \": \ "\", \ "방문객 신호 \": \ "방문객 기호 \": \ "81aebba9 - ddc3-4f58 - b1af - ac912d23a41e \ \ "MessageType \": \ "MessageTime \": \ "MessageType \": \ "NormalMessage \", \ "IsJoin \": \ "MessageTime \": \ "2017-02-07 10:57:13 \ \ "이름 \": \ "sathya \", \ "이메일 \": null, \ "IP \": null, \ "페이지 \": null, \ "등급 \": null, \ "이미지 \": \ "FileOploadDetails \": null, \ "FirstOperatorName \": \ "sathya \", \ "OperatorCount \": 1, \ "RequestTranscript \": null, \ "Country \ ": null, \"OS \ ": null, \"Broswer \ ": null, \"Mobi 제작 : \ "널 (null), \"iso_code의 \ "널 (null)}]"

방법

+ (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]; 
     } 
    } 
} 

이 고통은 하나의 \ 이모티콘이 있기 때문에 어떤 이모티콘이없는 경우이 방법은 잘 작동 NSJSONSerialization이 작동하지 않습니다. 어떤 사람이이 문제를 해결하도록 도와 줄 수 있습니까?

+0

확인하셨습니까? http://stackoverflow.com/questions/23814394/nsjsonserialization-and-emoji – User511

+0

"Two Hear emoji"를 사용하지 않으려면 공백 문자열로 바꾸어야합니다. 또는 유니 코드로 바꾸십시오. – Wolverine

+0

@ User511이 TNX를 사용했습니다. –

답변

1

문제는 JSON 문자열을 하드 코딩하고 변경하는 것입니다. JSON 문자열을 변경하지 않고 직접 NSData으로 변환하십시오.

NSData *data = [historyString dataUsingEncoding:NSUTF8StringEncoding]; 
NSError *error; 
NSMutableArray* jsonArray = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error]; 
NSLog(@"Array - %@", jsonArray); 
1

시도해보십시오. 당신이 어딘가에 그 이모티콘을 표시 한 다음 이모티콘으로 다시 변환 할 수 있습니다 원하는

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];