将值“System.Collections.Generic.List`1 []”转换为键入'WebApiTestDefinition.obJson'时出错。路径'',第1行,第63位

时间:2014-04-09 07:00:45

标签: c# asp.net-mvc asp.net-web-api

我试图反序列化json数据但它显示的错误是这样的。

public ActionResult Test(Login Log)      
{          
        string sStudName = "ram";
        HttpClient client = new HttpClient();
        client.BaseAddress = new Uri(StudentAPI);
        client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); // this depends on whether you want to get back json or XML            
        var loginResp = client.PostAsJsonAsync(StudentAPI, Log).Result;
        if (loginResp.IsSuccessStatusCode)
        {
            //if (loginResp == null)
            //{
                var msg = loginResp.Content.ReadAsStringAsync();                    
                obJson res = JsonConvert.DeserializeObject<obJson>(loginResp.Content.ReadAsStringAsync().Result);
                return Json(Log, JsonRequestBehavior.AllowGet);
            //}
            //return Redirect("/Admission/Registration");
        }
        else
        {

        }
        return View();
}

1 个答案:

答案 0 :(得分:0)

看看this question(它指的是JSON.net)

所以在你的情况下你应该尝试(如果可以使用JSON.net)

var msg = ""; // Get json message as string                    
dynamic json = JObject.Parse(msg); 
// Do something with this JSON