私はxCodeでアプリを作っています。.json ファイルから JSON データをロードするメソッドがあります。これは正常に機能し、viewcontroller は JSON オブジェクトを表示します (解析後)。コードは次のとおりです。
- (void) loadJsonData
{
//Create an URL
NSURL *url = [NSURL URLWithString:@"http://www....json"];
//Sometimes servers return a wrong header. Use this to add a new accepted type
[AFJSONRequestOperation addAcceptableContentTypes:[NSSet setWithObject:@"application/x-javascript"]];
//Create a request object with the url
NSURLRequest *request = [NSURLRequest requestWithURL:url];
//Create the JSON operation. The ^ blocks are executed when loading is done.
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
//Do something with the JSON data, like parsing
[self parseJSONData:JSON];
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
//Do something with the error
NSLog(@"Error :%@",response);
}];
//Start the operation
[operation start];
}
しかし、今は既存の .php ファイルから JSON オブジェクトを使用したいと考えています。URLを「http://www .... .php」に変更します。エラーは発生しませんでしたが、JSON が読み込まれません。ビューコントローラーにデータが表示されません。コード内の多くの変更を試みましたが、何も機能しません。.json url の代わりに .php を使用する場合、誰かが loadJsonData の正確なコードを教えてくれますか?
前もって感謝します!