2016-03-20 12 views
0

現在、My ControllerにJSONデータを送信する際に問題が発生しています。JSON.stringifyはネストされたオブジェクトを無視します

入れ子になっているオブジェクトを渡すと、入れ子になったオブジェクトはnullになることが分かりました。

[HttpPost] 
public ActionResult ApplyChanges(List<Change> pChanges) 
{ 
    //the Issue occurs here in every object of pChanges: 
    //IgnoreFlag was populated correctly, but the Detection Object is null...? 
} 

public class Change 
{ 
    public Detection Detection { get; set; } 
    public bool IgnoreFlag { get; set; } 
} 

私のクライアント側には次のようになります:

var data = [ 
    { 
    "Detection": { 
    "PropertyOld": 1, 
    "PropertyNew": 2, 
    }, 
    "IgnoreFlag": true 
    }, 
    { 
    "Detection": { 
    "PropertyOld": 3, 
    "PropertyNew": 4, 
    }, 
    "IgnoreFlag": false 
    } 
] 

$.ajax({ 
    type: "POST", 
    url: "/Url/To/ApplyChanges", 
    data: JSON.stringify({"pChanges": data}), 
    contentType: "application/json", 
    success: function (data, textStatus, jqXHR) { 
    //do something here 
}); 

誰かが私を解決するために助けることができます私は

私のサーバー側はこのようになります...私が欠けているかを把握することはできませんこの問題?

+0

を使用して、それはあなたの返信用 –

+0

おかげであるとしてだけ渡す、文字列化しないようにしてみてください。私はそれを試したが、うまくいかない。同じ結果です.. – Alan

+0

オブジェクトを 'JSON.stringify'しても何も無視されません。 https://jsfiddle.net/qz3vp6gx/ –

答えて

1

使用

JSON.stringify(data) 

代わりの

JSON.stringify({"pChanges": data}) 
関連する問題