开发者

i am not able to convert nsmutable data to string

hi i am getting data through webservice using JSON

i get the开发者_JS百科 responseData but i don't know why it is not convert in to string

this is my code: - (void)connectionDidFinishLoading:(NSURLConnection *)connection {

NSString *string = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
NSLog(@"string %@",string);
NSMutableDictionary *dict = [string JSONValue];
NSLog(@" Dict %@", dict);
[infoArray removeAllObjects];
NSMutableArray *array = [dict objectForKey:@"Premio"]; 
[infoArray addObjectsFromArray:array];
NSLog(@" Array1 : %@",infoArray);  

the output is like 2011-04-06 12:12:52.694 Monforte[1720:207] response DATA <7b225072 656d696f 223a207b 2273436f 64696365 223a2022 39383422 2c226964 5072656d 696f223a 20223836>

2011-04-06 12:12:52.695 Monforte[1720:207] string (null)

2011-04-06 12:12:52.696 Monforte[1720:207] Dict (null)

2011-04-06 12:12:52.697 Monforte[1720:207] Array1 : (

)


Since NSString's -initWithData:encoding: method returns nil if the data isn't valid for the given encoding, that's the first thing I'd check for. Check the response HTTP headers to make sure the server says you're supposed to be receiving UTF-8 encoded text. If so, try saving the received data straight to a file with NSData's -writeToFile:atomically: method and opening it in a text editor (such as TextWrangler) to verify that it really is UTF-8.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜