0

API と通信するアプリケーションを作成したいのですが、解析の何が問題なのかわかりませんでした。

コードは次のとおりです。

 NSJSONSerialization *jsonObject = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];

NSLog(@" jsonObject: %@", jsonObject);

NSURL *img1 = [[NSURL alloc] initWithString:[jsonObject obj]];
NSURL *img2 = [[NSURL alloc] initWithString:[jsonObject valueForKey:@"img2"]];
NSURL *img3 = [[NSURL alloc] initWithString:[jsonObject valueForKey:@"img3"]];
NSData *data1 = [[NSData alloc] initWithContentsOfURL:img1];
NSData *data2 = [[NSData alloc] initWithContentsOfURL:img2];
NSData *data3 = [[NSData alloc] initWithContentsOfURL:img3];
UIImage *image1 = [[UIImage alloc] initWithData:data1];
UIImage *image2 = [[UIImage alloc] initWithData:data2];
UIImage *image3 = [[UIImage alloc] initWithData:data3];

そして、ここにツリーがあります:

jsonObject: (
    {
    img1 = "http://www.kozpontiszalon.hu/images/ads/kupon_aug_3.png";
    img2 = "anotherlink";
    img3 = "anotherlink";
    }
)

助けてくれてありがとう!

4

1 に答える 1

1

最初の行は次のようになります。

NSArray *jsonObject = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];

JSON データは配列であるためです。

この配列には、画像 URL を含む単一の辞書があります。

NSDictionary *urls = jsonObject[0];
NSURL *img1 = [[NSURL alloc] initWithString:urls[@"img1"]];
于 2013-08-16T22:37:15.797 に答える