0

次のように、JSON オブジェクトを asp.net mvc コントローラー アクションに投稿しています。コントローラー アクションは、json 変数を個々のオブジェクトに自動的にバインドします。これは優れた機能ですが、私の要件は、着信 json 文字列を「そのまま」単一の文字列オブジェクトにキャプチャし、データベースに保存することです。私の質問は、デフォルトの動作をオーバーライドして、着信 json オブジェクトを単一の文字列で取得するにはどうすればよいですか?

見る

$.ajax({
            type: "POST",
            url: "@(storeLocation)IDR/OpcInsertCustomerProfile/",
            data: JSON.stringify(currSelection),
            contentType: "application/json",
            success: function(data) {
              alert('success : ' + JSON.stringify(data));
            },
            error: function(data) {
             alert('Error : ' + JSON.stringify(data));
            }
          }
        );

コントローラ

[HttpPost]
        [ActionName("OpcInsertCustomerProfile")]
        public JsonResult OpcInsertCustomerProfile(string jsonProfile)
        {
            try
            {
                JavaScriptSerializer ser = new JavaScriptSerializer();
                return Json(jsonProfile, JsonRequestBehavior.AllowGet);

            }
            catch (Exception exc)
            {
                return Json(new { error = 1, message = exc.Message });
            }
        }
4

2 に答える 2

0

このようなことを試すことができます コンテンツをjsonに戻す

System.Web.Script.Serialization.JavaScriptSerializer oSerializer = 
     new System.Web.Script.Serialization.JavaScriptSerializer();

string sJSON = oSerializer.Serialize(oList);


[{"Name":"Pini","Age":"30","ID":"111"},
{"Name":"Yaniv","Age":"31","ID":"Cohen"},
{"Name":"Yoni","Age":"20","ID":"Biton"}]

ここを参照

于 2012-09-27T11:21:43.113 に答える
0

オブジェクトを使用するHttpRequestと、そのオブジェクトから生データを取得できるフォーム変数コレクションがあります。

string rawdata = Request.Form["variable name"];

変数名を見つける必要があります。

デバッガーを使用してこれを確認できます。

于 2012-09-27T08:43:18.260 に答える