views:

53

answers:

3
+1  Q: 

unicode to zh-cN

NSArray *array=[contentOfResponseDataInJsonValue JSONValue];
NSLog(@"%@",array); 

prints:

(
    (
        (
        "\U515c\U639b\U8e55",
        AABENRAA,
        " o b\U8c46n lu\U8eab"
        )
    ),
    (
    ),
    en
)

but

if (array==nil) {
    return returnStr=@"";
}else {
    returnStr=[[[array objectAtIndex:0] objectAtIndex:0] objectAtIndex:0] ;
}
NSLog(@"result is %@",returnStr);

show :兜掛蹕

\U515c\U639b\U8e55 to 兜掛蹕 why ,why!

please help me !!! thanks!

A: 

I looked up the Unicode table, and indeed

  • \U515c is 兜 ,
  • \U639b is 掛 ,
  • \U8e55 is 蹕 .

The combination of those three letters doesn't make sense to me (as a Japanese), but that's what you have in JSON data.

What do you want to do? In order to be helped, you need to explain about what you want to be helped.

Yuji
oh,sorry!NSString *strURL=[NSString stringWithFormat:@"http://translate.google.cn/translate_a/t?client=tNSURL *url=[[NSURL alloc] initWithString:strURL];NSString *contentOfResponseDataInJsonValue=[NSString stringWithContentsOfURL:url encoding:encoder=-2147483646 error: NSLog(@"%@",url); why i copy url in browser。return result is [[["奥本罗","AABENRAA","Ào běn luō"]],,"en"]. but NSLog(@"%@",contentOfResponseDataInJsonValue); print [[["兜掛蹕","AABENRAA"," o b豆n lu身"]],,"en"].
raien
I still don't understand. Please explain what you want to achieve. Posting "this code does A, that code does B" doesn't tell us what you want to do.
Yuji
A: 

oh,sorry!

NSString *strURL=[NSString stringWithFormat:@"http://translate.google.cn/translate_a/t?client=t&text=%@&hl=zh-CN&sl=%@&tl=%@&multires=1&otf=2&pc=0&sc=1",strTextOfFilter,@"en", @"zh-CN" ];

 NSURL *url=[[NSURL alloc] initWithString:strURL];

 NSString *contentOfResponseDataInJsonValue=[NSString stringWithContentsOfURL:url encoding:encoder=-2147483646 error:&error];
    NSLog(@"%@",url); 

why i copy url in browser。return result is [[["奥本罗","AABENRAA","Ào běn luō"]],,"en"]. but

NSLog(@"%@",contentOfResponseDataInJsonValue); 

print [[["兜掛蹕","AABENRAA"," o b豆n lu身"]],,"en"]. why show this!

 contentOfResponseDataInJsonValue=[contentOfResponseDataInJsonValue stringByReplacingOccurrencesOfString:@",,"withString:@",[],"];
 NSArray *array=[contentOfResponseDataInJsonValue JSONValue];
raien
You should edit it into the question, not post an answer.
KennyTM
+1  A: 
NSString *contentOfResponseDataInJsonValue = 
   [NSString stringWithContentsOfURL:url encoding:encoder=-2147483646 error:&error];
//                                                ^^^^^^^^^^^^^^^^^^^

What is this? You are using the encoding 0x80000002 which is not documented anywhere. Since translate.google.com is returning UTF-8 result, you should write

NSString *contentOfResponseDataInJsonValue = 
   [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:&error];

or let the system determines the encoding for you,

NSString *contentOfResponseDataInJsonValue = 
   [NSString stringWithContentsOfURL:url usedEncoding:&encoding error:&error];
KennyTM