Just a Computer Graphics Studio & My Life

哈~不知道怎麼下標題,不過直接看圖和程式碼就能懂囉~

如果用post把資料傳到server上,參數是arraydictionary時,key和value要怎麼下呢?

POST array dictionary

這是在PostMan上下KeyValue

iOS程式可以依樣畫葫蘆~自己創造key,value不變,全部塞到要POST出去的dictionary中。

    for (int i = 0; i < [photoDetail count]; i++) {
        key = [NSString stringWithFormat:@"photos_detail[%i][photo_name]",i];
        value = photoDetail[i][@"photo_name"];
        [parameters setValue:value forKey:key];

        key = [NSString stringWithFormat:@"photos_detail[%i][photo_rate]",i];
        value = photoDetail[i][@"photo_rate"];
        [parameters setValue:value forKey:key];

        key = [NSString stringWithFormat:@"photos_detail[%i][photo_start_x]",i];
        value = photoDetail[i][@"photo_start_x"];
        [parameters setValue:value forKey:key];

        key = [NSString stringWithFormat:@"photos_detail[%i][photo_start_y]",i];
        value = photoDetail[i][@"photo_start_y"];
        [parameters setValue:value forKey:key];
    }
    [parameters setValue:typeOption[@"new_type"] forKey:@"type_option[new_type]"];
    [parameters setValue:typeOption[@"start_year"] forKey:@"type_option[start_year]"];
    [parameters setValue:typeOption[@"start_month"] forKey:@"type_option[start_month]"];

程式印出結果:

parameters:{
“photos_detail[1][photo_name]" = “3/3_FR2013-10-16_1.jpg";
“photos_detail[1][photo_rate]" = “";
“photos_detail[1][photo_start_x]" = “";
“photos_detail[1][photo_start_y]" = “";
“photos_detail[2][photo_name]" = “3/3_FR2013-10-16_2.jpg";
“photos_detail[2][photo_rate]" = “";
“photos_detail[2][photo_start_x]" = “";
“photos_detail[2][photo_start_y]" = “";
“photos_detail[3][photo_name]" = “3/3_FR2013-10-16_3.jpg";
“photos_detail[3][photo_rate]" = “";
“photos_detail[3][photo_start_x]" = “";
“photos_detail[3][photo_start_y]" = “";

“type_option[new_type]" = 1;
“type_option[start_month]" = 12;
“type_option[start_year]" = 2013;
}

如此POST送出到server就有效果囉~

參考:Is it possible to send an array with the Postman Chrome extension?

廣告

發表留言

在下方填入你的資料或按右方圖示以社群網站登入:

WordPress.com Logo

您的留言將使用 WordPress.com 帳號。 登出 / 變更 )

Twitter picture

您的留言將使用 Twitter 帳號。 登出 / 變更 )

Facebook照片

您的留言將使用 Facebook 帳號。 登出 / 變更 )

Google+ photo

您的留言將使用 Google+ 帳號。 登出 / 變更 )

連結到 %s

標籤雲

%d 位部落客按了讚: