1

我在 Rails 中看到一个奇怪的问题。

请求正文(request.body):

renewals[][driver_1][dl_number]=123&
renewals[][driver_1][expiration_date]=20130513&
renewals[][driver_1][last_name]=123&
renewals[][driver_1][state]=AL&
renewals[][driver_1][verified]=1&
renewals[][driver_2][verified]=0&
renewals[][id]=6415&
renewals[][insurance][expiration_date]=20130513&
renewals[][insurance][naic]=123&
renewals[][insurance][policy_number]=123&
renewals[][insurance][verified]=1&
renewals[][mailing_address][address_has_changed]=0&
renewals[][mailing_address][city]=GULF%20SHORES&
renewals[][mailing_address][state]=AL&
renewals[][mailing_address][street_address]=8094%20BEACH%20LANE&
renewals[][mailing_address][zip]=35023&
renewals[][driver_1][dl_number]=123&
renewals[][driver_1][last_name]=123&
renewals[][driver_1][state]=AL&
renewals[][driver_1][verified]=1&
renewals[][driver_2][verified]=0&
renewals[][id]=6412&
renewals[][insurance][expiration_date]=20130513&
renewals[][insurance][naic]=123&
renewals[][insurance][policy_number]=123&
renewals[][insurance][verified]=1&
renewals[][mailing_address][address_has_changed]=0&
renewals[][mailing_address][city]=HUEYTOWN&
renewals[][mailing_address][state]=AL&
renewals[][mailing_address][street_address]=123%20ANY%20LANE&
renewals[][mailing_address][zip]=35023&
renewals[][driver_1][dl_number]=123&
renewals[][driver_1][last_name]=123&
renewals[][driver_1][state]=AL&
renewals[][driver_1][verified]=1&
renewals[][driver_2][verified]=0&
renewals[][id]=6411&
renewals[][insurance][expiration_date]=20130513&
renewals[][insurance][naic]=123&
renewals[][insurance][policy_number]=123&
renewals[][insurance][verified]=1&
renewals[][mailing_address][address_has_changed]=0&
renewals[][mailing_address][city]=HUEYTOWN&
renewals[][mailing_address][state]=AL&
renewals[][mailing_address][street_address]=104%20MERRIMONT%20ROAD&
renewals[][mailing_address][zip]=35023&

JSON 解析参数(params[:renewals]):https ://gist.github.com/t2/5566652

请注意,在 JSON 中,最后一条记录中缺少 driver_1 信息。不知道为什么会这样。数据在请求中。我缺少任何已知的错误吗?如果您需要更多信息,请告诉我。

4

2 回答 2

0

不幸的是,这正是 Rails 解析 JSON 的方式(你[]的嵌套很大)。我之前遇到过这个问题 - http://guides.rubyonrails.org/form_helpers.html#combining-them给出了一些解释。

据我记得,如果您可以输入数字键而不仅仅是[](即[1]第一个,[2]第二个等),那么它将按您的意愿工作。

于 2013-05-13T10:25:45.387 回答
0

所以我想通了。我需要设置requestSerializationMIMETypeRKMIMETypeJSON.

于 2013-05-14T04:54:57.777 回答