I have some python code for Google App Engine that responds with the string {"sample_list": [{"message": "Hello, world.", "name": "Human"}]}
I am using this JSON-framework developed by sbrautaset to convert the string to an object that I can use (NSDictionary in this case). I am following the tutorial here to use the framework.
My problem is that I am getting null for [jsonParser objectWithString:jsonString error:NULL]
where jsonString is {"sample_list": [{"message": "Hello, world.", "name": "Human"}]}
and jsonParser is an instance of SBJSON
from the framework.
I am guessing that the parser is not recognizing the string as a JSON format. Any insight would be appreciated, as I am completely new to JSON.
Thank you!
UPDATE: The Server Side Python Code
outer_dict = {}
middle_list = []
inner_dict = {}
inner_dict["name"] = "Human"
inner_dict["message"] = "Hello, world."
middle_list.append(inner_dict)
outer_dict["sample_list"] = middle_list
json_message = simplejson.dumps(outer_dict)
self.response.out.write(json_message)
The Client Side Objective-C Code
NSURL *url = [NSURL URLWithString:@"http://theurl"];
NSString *jsonString = [self stringWithUrl:url];
NSLog(@"%@", jsonString);
id myObj = [jsonString JSONValue];
NSLog(@"%@", myObj);
stringWithUrl
- (NSString *) stringWithUrl:(NSURL *)url {
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url
cachePolicy:NSURLRequestReturnCacheDataElseLoad
timeoutInterval:30];
NSData *urlData;
NSURLResponse *response;
NSError *error;
urlData = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&response error:&error];
return [[NSString alloc] initWithData:urlData encoding:NSUTF8StringEncoding];
}