0

这是我得到的响应数据。有人可以知道如何解析这些数据吗?

"message":{
       "amount":{"notFloat":"'asd' does not appear to be a float"},
       "lastname":{"notEmpty"}:"lastname must be required"},
       etc....
 }

我想要的是以组织格式显示所有检测到的错误。

options.save(d, {
                success: function (model, response) {
                    if(response['status'] == 'success'){
                        alert = new AlertView({type: 'success', message: 'New record successfully added.'}); 
                    } else {
                         alert = new AlertView({type: 'error', message: response['message']});
                    }
                    alert.render();
                },
                error: function (model, response) {
                    alert = new AlertView({type: 'error', message: response});
                    alert.render();
                }
            });
4

1 回答 1

0
data = $.parseJSON(jsonAsTextFromServer);
$.each( data.message, function( key, value ) {
    $.each( value, function( err_key, err_value ) {
        alert( key + "::" + err_key + ": " + err_value );
    });

});

顺便说一句,此响应格式不正确。它应该由 { } 包裹

演示(更新)

于 2013-07-29T10:10:30.457 回答