如何在Objective-C中输出JSon数据 [英] How to output JSon data in Objective-C

查看:121
本文介绍了如何在Objective-C中输出JSon数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用iPhone应用程序,该应用程序从以下来源获取数据:

I am currently working on an iPhone application that takes in data from the following source:

我正在尝试找出如何在一个文本字段中将其解析为人类可读的格式.

I am trying to figure out how to parse it into a human readable format in say a text field.

到目前为止,我的代码是:

My code so far is:

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    NSString *urlString = [NSString stringWithFormat:@"http://dev.threesixtyapp.com/api/events.php?action=available&id=1"];
    NSURL *url =[NSURL URLWithString:urlString];
    NSData *data = [NSData dataWithContentsOfURL:url];
    NSError  *error;
    NSMutableDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
    NSLog(@"%@",json);
}

推荐答案

http://stig.github .com/json-framework/-SBJson是一个用于JSON编码/解码的出色框架.我建议您检查一下...它将为您解析为NSDictionary,您只需将文本字段的文本设置为等于所需的NSDictionary中的值即可.使用此框架非常简单.当您将Json传递给SBJson函数btw时,它应该只是一个字符串

http://stig.github.com/json-framework/ - SBJson is a great framework for encoding/decoding JSON. I recommend you check it out...It will parse it for you into an NSDictionary, and you simply set the text of the textfield equal to the value in the NSDictionary that you want. It's pretty straightforward using this framework. Your Json should just be a string when you pass it to the SBJson functions btw

这篇关于如何在Objective-C中输出JSon数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆