Hello,
So right now I am having issues parsing JSON for an application that I am working on. I am using the Stig Brautaset JSON classes to attempt to parse JSON from google reader here's an example:
This is the code that I am using to parse it:
Which is not working, it returns this error:
I'm new to JSON and can't seem to figure out why this isn't working, what am I doing wrong?
Thanks for any help.
So right now I am having issues parsing JSON for an application that I am working on. I am using the Stig Brautaset JSON classes to attempt to parse JSON from google reader here's an example:
Code:
{
"author": "Harry",
"continuation": "...",
"direction": "ltr",
"id": "user/userid/state/com.google/reading-list",
"items": [
{
"alternate": [
{
"href": "http://www.test.com/article.html",
"type": "text/html"
}
],
"annotations": [
],
"author": "",
"categories": [
"cat1",
"cat2"
],
"comments": [
],
"crawlTimeMsec": "1332983007944",
"id": "tag:google.com,2005:reader/item/90cd9acd9c62942f",
"likingUsers": [
],
"origin": {
"htmlUrl": "http://www.test.com",
"streamId": "feed/http://www.test.com/rss.xml",
"title": "Test XML"
},
"published": 1332982620,
"summary": {
"content": " Amazing Content",
"direction": "ltr"
},
"timestampUsec": "1332983007944330",
"title": "An Amazing Article",
"updated": 1332982620
}
],
"title": "Harry's reading list in Google Reader",
"updated": 1332983007
}
This is the code that I am using to parse it:
Code:
#import "JSONTestViewController.h"
#import "JSON.h"
@implementation JSONTestViewController
@synthesize responseData;
#pragma mark -
#pragma mark Fetch loans from internet
-(void)loadData
{
self.responseData = [NSMutableData data];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.google.com/reader/api/0/stream/contents/user/-/state/com.google/reading-list?ot=1253066400&r=n&xt=user/-/state/com.google/read&n=2&ck=1255660536125&client=myApplication"]];
[[NSURLConnection alloc] initWithRequest:request delegate:self];
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
[responseData setLength:0];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[responseData appendData:data];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
[connection release];
self.responseData = nil;
}
#pragma mark -
#pragma mark Process loan data
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
[connection release];
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
self.responseData = nil;
NSArray* items = [(NSDictionary*)[responseString JSONValue] objectForKey:@"items"];
[responseString release];
//choose a random loan
NSDictionary* item = [items objectAtIndex:1];
NSString* name = [item objectForKey:@"title"];
//set the text to the label
label.text = name; //[NSString stringWithFormat:@"%@ - %@", name,author];
}
@end
Which is not working, it returns this error:
-JSONValue failed. Error trace is: (
"Error Domain=org.brautaset.JSON.ErrorDomain Code=3 \"Unrecognised leading character\" UserInfo=0x6b7b130 {NSLocalizedDescription=Unrecognised leading character}"
)
I'm new to JSON and can't seem to figure out why this isn't working, what am I doing wrong?
Thanks for any help.