POST json dictionary

后端 未结 10 917
猫巷女王i
猫巷女王i 2020-11-27 05:52

I\'m trying the following : A model with a dictionary inside send it on the first ajax request then take the result serialize it again and send it back to the controller.

10条回答
  •  忘掉有多难
    2020-11-27 06:26

    Just use a better deserializer. That first line where I set the position is because the JsonValueProvider leaves the stream at the end. More MS JSON fail.

    Request.InputStream.Position = 0;
    var reader = new StreamReader(Request.InputStream);
    
    var model = Newtonsoft.Json.JsonConvert.DeserializeObject(reader.ReadToEnd());
    

    So somewhere in that CreativeUploadModel object graph there is a prop like this:

    public Dictionary Assets { get; set; }
    

    Which is deserialized from (for example):

    "assets":{"flash":{"type":"flash","value":"http://1234.cloudfront.net/1234.swf","properties":"{\"clickTag\":\"clickTAG\"}"}
    

    Newtonsoft JSON is the default JSON provider for WebAPI... so it's not going anywhere.

提交回复
热议问题