0

JSON 解析を使用しています。データをJSON Arrayという名前の配列に入れます。コンソールでは次のようになります

JSON Array=(
 {
    "created_by" = 42;
    "created_on" = "2012-02-29 11:23:37";
    "file_description" = "";
    "file_is_downloadable" = 0;
    "file_is_forSale" = 0;
    "file_is_product_image" = 1;
    "file_meta" = "";
    "file_mimetype" = "image/jpeg";
    "file_params" = "";
    "file_title" = "hand shovel";
    "file_type" = product;
    "file_url" = "images/stories/virtuemart/product/cca3cd5db813ee6badf6a3598832f2fc.jpg";
    "file_url_thumb" = "images/stories/virtuemart/product/resized/cca3cd5db813ee6badf6a3598832f2fc_90x90.jpg";
    "locked_by" = 0;
    "locked_on" = "0000-00-00 00:00:00";
    "modified_by" = 42;
    "modified_on" = "2012-02-29 11:23:37";
    ordering = 0;
    "product_name" = "Hand Shovel";
    published = 0;
    shared = 0;
    "virtuemart_category_id" = 1;
    "virtuemart_media_id" = 13;
    "virtuemart_product_id" = 1;
    "virtuemart_vendor_id" = 1;
},

    {
    "created_by" = 42;
    "created_on" = "2012-02-29 11:35:09";
    "file_description" = "";
    "file_is_downloadable" = 0;
    "file_is_forSale" = 0;
    "file_is_product_image" = 1;
    "file_meta" = "";
    "file_mimetype" = "image/jpeg";
    "file_params" = "";
    "file_title" = "our ladder";
    "file_type" = product;
    "file_url" = "images/stories/virtuemart/product/8cb8d644ef299639b7eab25829d13dbc.jpg";
    "file_url_thumb" = "images/stories/virtuemart/product/resized/8cb8d644ef299639b7eab25829d13dbc_90x90.jpg";
    "locked_by" = 0;
    "locked_on" = "0000-00-00 00:00:00";
    "modified_by" = 42;
    "modified_on" = "2012-02-29 11:35:09";
    ordering = 0;
    "product_name" = Ladder;
    published = 0;
    shared = 0;
    "virtuemart_category_id" = 3;
    "virtuemart_media_id" = 8;
    "virtuemart_product_id" = 2;
    "virtuemart_vendor_id" = 1;
}, 

これから、実際には別の配列の画像である「 file_url_thumb 」を選択する必要があります。どうすればこれを行うことができますか教えてください。

4

3 に答える 3

1
//Your array has two dictionary ..


for(NSMutableDictionary *dict in JSON_Array){
       NSString *urlString =  [dict objectForKey:@"file_url_thumb"];
       if(urlString){
       NSURL *url = [NSURL urlWithString:urlString];
       NSData* imageData = [[NSData alloc] initWithContentsOfURL:url]];
       UIImage* image = [[UIImage alloc] initWithData:imageData];
       //show your image on imageview
      }
}

これがあなたを助けることを願っています

于 2012-06-15T09:50:50.950 に答える
0
NSString *urlString = [[jsonArray objectAtIndex:0] objectForKey:@"file_url_thumb"];

これにより、「file_url_thumb」の値が文字列として得られます。

于 2012-06-15T09:53:37.240 に答える
0
NSString *str_URL =[ [json objectAtIndex:anIndex] valueForKey:@"file_url_thumb"];
于 2012-06-15T09:48:24.607 に答える