我得到" System.ArgumentException:无效的JSON原语:"我正在使用fiddler4测试我的asp.net web api。
标题如下
Content-Type: multipart/form-data; boundary=-------------------------acebdf13572468
User-Agent: Fiddler
Host: tr****ro.in
Content-Length: 8976
正文如下
---------------------------acebdf13572468
Content-Disposition: form-data; name="json"
Content-Type: application/json
{
"WR_id":"0",
"Com_Id": "5",
"Usr_Id":"22",
"WRC_id":"1",
"App_id":"1",
"Ser_LogNo":"2",
"WR_Comments":"Test",
"WR_date":"2015-12-23 01:30:50.000",
"WR_Location":"test",
"WR_lati":"10.45465",
"WR_longi":"70.23654",
"Status_id":"11"
}
---------------------------acebdf13572468
Content-Disposition: form-data; name="fieldNameHere"; filename="download (1).png"
Content-Type: image/png
<@INCLUDE *C:\Users\MANU\Desktop\cv\download (1).png*@>
---------------------------acebdf13572468
Content-Disposition: form-data; name="fieldNameHere"; filename="download.png"
Content-Type: image/png
<@INCLUDE *C:\Users\MANU\Desktop\cv\download.png*@>
---------------------------acebdf13572468--
控制器如下
[HttpPost]
public async Task<HttpResponseMessage> PostFormData()
{
Work_Report_image image = new Work_Report_image();
Tempsave save = new Tempsave();
if (!Request.Content.IsMimeMultipartContent())
{
throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
}
string root = HttpContext.Current.Server.MapPath("~/App_Data/");
var provider = new MultipartFormDataStreamProvider(root);
await Request.Content.ReadAsMultipartAsync(provider);
try
{
if (provider.FormData.AllKeys.AsParallel().Contains("json"))
{
//foreach (var val in provider.FormData.GetValues(key))
//{
using (var scope = new System.Transactions.TransactionScope())
{
string json= provider.FormData.GetValues("json").SingleOrDefault();
Work_Report Work_Report = js.Deserialize<Work_Report>(json);
我得到的错误如下:
System.ArgumentException: Invalid JSON primitive: "0", "Com_Id": "5", "Usr_Id":"22", "WRC_id":"1", "App_id":"1", "Ser_LogNo":"2", "WR_Comments":"Test", "WR_date":"2015-12-23 01:30:50.000", "WR_Location":"test", "WR_lati":"10.45465", "WR_longi":"70.23654", "Status_id":"11" }. at System.Web.Script.Serialization.JavaScriptObjectDeserializer.BasicDeserialize(String input, Int32 depthLimit, JavaScriptSerializer serializer) at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(JavaScriptSerializer serializer, String input, Type type, Int32 depthLimit) at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize[T](String input) at WebApplication.Areas.Json.Controllers.Work_ReportController.d__4.MoveNext()