基本上我正在尝试从自定义搜索引擎中检索 json 数据,但我没有成功(链接只是一个占位符,无法显示真实链接)。我将发布我的目标 c 代码,并在底部显示我的 json 代码。基本上我试图从中检索 TermText,但我没有成功。我基本上是从 bing 教程中撕下这段代码。任何帮助将不胜感激。现在,代码给了我一个控制台日志 nil。
。H
@interface ViewController : UIViewController{
NSString *jsonstring;
}
@property (nonatomic,retain)NSString *offValue;
-(void) searchBing:(NSString *)text;
-(void)getData:(NSData *) response;
.m
-(void)searchBing:(NSString *)text{
//MODIFY
NSString *urlString=[NSString stringWithFormat:@"%@%@%@%@",@"http://api/text data.",text,@"&sources=web&web.offset=",offValue];
NSURL *url =[NSURL URLWithString:urlString];
NSData *data =[NSData dataWithContentsOfURL:url];
[self getData:data];
}
-(void)getData:(NSData *)response{
NSError *error;
NSMutableDictionary *json = [NSJSONSerialization JSONObjectWithData:response options:kNilOptions error:&error];
NSLog(@"%@",json);
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
offValue =@"0";
[self searchBing:@"Term"];
}
json
{
"ReturnValue": [
{
"Term": {
"TermID": 1,
"TermText": "sample string 2",
"Description": "sample string 3"
}
},
{
"Term": {
"TermID": 1,
"TermText": "sample string 2",
"Description": "sample string 3"
}
},
{
"Term": {
"TermID": 1,
"TermText": "sample string 2",
"Description": "sample string 3"
}
}
],
"ResultCode": 0,
"ResultCodeName": 0,
"ErrorMessage": "sample string 2"
}