2012-06-15 29 views
0

我正在使用JSON解析,我把數據放在數組中名爲JSON數組。在控制檯看起來如何從數組中解析JSON中選擇圖像

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」,這實際上是在單獨的陣列圖像。 請讓我知道我該怎麼做?

+0

你有什麼試過?顯示解析JSON和解壓縮數據的代碼,並說明您嘗試過的方式以及它以何種方式無效。我們不在這裏爲你寫代碼。 –

+0

此外,我們可以看到他們是兩個組別,其中獨立的「virtuemart_category_id」是那裏取決於該ID如何可以將該完整的組內容放在其他數組 –

+0

@NickBull其實我首先需要將這兩個組分成兩個數組,取決於「virtuemart_category_id」爲此我正在使用文本字段。即如果在文本字段中輸入3,則組內容「virtmart_category_id」= 3必須在其他數組中分離。然後出於這一點,我需要搜索「file_url_thumb」這實際上是圖像,以顯示在圖像視圖 –

回答

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 
     } 
} 

希望這將幫助你

+0

謝謝阿布舍克...! –

+0

您的歡迎ajit .. :) – Abhishek

0
NSString *str_URL =[ [json objectAtIndex:anIndex] valueForKey:@"file_url_thumb"]; 
0
NSString *urlString = [[jsonArray objectAtIndex:0] objectForKey:@"file_url_thumb"]; 

這會給你的 「file_url_thumb」 作爲一個字符串值。