Converting NSMutableData to NSString Problem
init开发者_如何学CWithData does not convert my data object into a string properly. When I check the length of the data object, it has a value.
NSMutableData* receivedData =[[NSMutableData data] retain];
NSString* json_string = [[NSString alloc] initWithData:receivedData encoding:NSUTF8StringEncoding];
Am I doing something wrong creating the string?
As posted, the code is nonsense. You are creating an empty immutable data and then trying to create a string from said empty data.
What does * When I check the length of the data object, it has a value* mean? Do you mean that you have more code that you aren't showing? Something that is filling the mutable data with some bytes?
Also, if the received data is not actually encoded as a UTF-8 string, the conversion will fail. There are a number of methods on NSString that allow for lossy conversion. Try one of those.
I didn't fully complete the NSURLConnection delegate methods. This is where my data is being built.
精彩评论