【发布时间】:2014-09-03 11:31:45
【问题描述】:
亲爱的程序员。 我必须连接到一个 api 并使用我返回的 json 将它存储在一个表中。 使用 AFnetworking、Xcode 和 ios。 到目前为止,它已经折磨了我一整天,让我发疯。我已经尝试了几个教程和项目,但我无法让它发挥作用。
第一个问题是我似乎无法在我返回的 json 中找到我的密钥..
当然我必须解析 json,这对我也不起作用
你能帮我把我的 json 放到表格视图中吗?
我使用的api是:https://api.9292.nl/0.1/locations?lang=nl-NL&q=amsterd
我在应用程序中收到的 json 作为输出是 {
"locations": [
{
"id": "station-amsterdam-centraal",
"type": "station",
"stationId": "asd",
"stationType": "Station",
"name": "Amsterdam Centraal",
"place": {
"name": "Amsterdam",
"regionCode": "NH",
"regionName": "Noord-Holland",
"showRegion": false,
"countryCode": "NL",
"countryName": "Nederland",
"showCountry": false
},
"latLong": {
"lat": 52.378706,
"long": 4.900489
},
"urls": {
"nl-NL": "/station-amsterdam-centraal",
"en-GB": "/en/station-amsterdam-centraal"
}
等
The code I have right now is:
//
// ViewController.m
// 9292apiconnection
//
// Created by TheDutchBeast on 02-09-14.
// Copyright (c) 2014 Lambregts. All rights reserved.
//
#import "ViewController.h"
#import <AFNetworking/AFNetworking.h>
@interface ViewController ()
@property (strong, nonatomic) NSDictionary *posts;
@property (strong, nonatomic) NSMutableArray *post;
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager GET:@"http://api.9292.nl/0.1/locations?lang=nl-NL&q=amsterd" parameters:nil success:^(
AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"JSON: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
请帮助我从 json 代码中定义键以及如何将这些值放入 Xcode 、 ios 中的表中 .表格中只需要显示ID和NAME
请不要链接到教程,因为我都看过了 提前致谢
【问题讨论】:
标签: ios objective-c json parsing