我使用在github上(辉煌的东西)发现SBJson框架https://github.com/stig/json-framework/修改SBJson framwork我的应用程序
与例如:http://blog.zachwaugh.com/post/309924609/how-to-use-json-in-cocoaobjective-c
这叽叽喳喳比如现在的伟大工程。
所以我改变我的网址和
for (NSDictionary *status in statuses)
{
// You can retrieve individual values using objectForKey on the status NSDictionary
// This will print the tweet and username to the console
NSLog(@"%@ - %@", [status objectForKey:@"text"], [[status objectForKey:@"user"] objectForKey:@"screen_name"]);
}
到
for (NSDictionary *status in statuses)
{
// You can retrieve individual values using objectForKey on the status NSDictionary
// This will print the tweet and username to the console
NSLog(@"%@ - %@", [status objectForKey:@"text"], [[status objectForKey:@"message"] objectForKey:@"nationalad"]);
}
所以我在我的网页JSON有消息:和nationalad:但我没有得到任何回报或或登录打印出。这些是我改变的唯一的两件事。
任何想法?
这是编辑:
SBJsonParser *parser = [[SBJsonParser alloc] init];
// Prepare URL request to download statuses from Twitter
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.mywebpagehere.com"]];
// Perform request and get JSON back as a NSData object
NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
// Get JSON as a NSString from NSData response
NSString *json_string = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];
// parse the JSON response into an object
// Here we're using NSArray since we're parsing an array of JSON status objects
NSArray *statuses = [parser objectWithString:json_string error:nil];
// Each element in statuses is a single status
// represented as a NSDictionary
for (NSDictionary *status in statuses)
{
// You can retrieve individual values using objectForKey on the status NSDictionary
// This will print the tweet and username to the console
//NSLog(@"%@ - %@", [status objectForKey:@"text"], [[status objectForKey:@"message"] objectForKey:@"nationalad"]);
// NSLog(@"Message: %@", [status objectForKey:@"message"]);
}
// NSDictionary *json = [NSString JSONValue];
NSLog(@"Status: %@", statuses);
// NSArray *items = [statuses valueForKeyPath:@"data.array"];
//NSLog(@"message : %@", [[items objectAtIndex:1] objectForKey:@"message"]);
和服务器页面:
{
'message': "<p style=\"color:#FFFFFF;font-family:'Century Gothic',futura,'URW Gothic L',Verdana,sans-serif;\">Welcome!<\/p><p style=\"color:#FFFFFF;font-family:'Century Gothic',futura,'URW Gothic L',Verdana,sans-serif;\">Check out today's Dinner and Lunch specials below!<\/p>",
'nationalad': "<img src='http:\/\/www.mywebpage.com\/images\/national\/fullrz_3_4e81fa75ceba5_mywebpage.JPG'>"
}
请编辑您的问题,并发布你试图解析JSON字符串,以及你使用解析代码它(从JSON字符串开始)。 – 2011-09-30 20:36:10
NSLog(@“状态:%@”,状态);返回null – Rick
在您发布的代码中作为答案(您不应该这样做,因为它不是答案;您应该已经编辑了您的问题),如果status为'nil',那么您应该也有一个答案解析错误信息。什么是错误信息? 'json_string'的内容是什么? – 2011-10-02 23:31:43