I am using json.net to deserialize incoming json in a WebApi service.
var lines = JsonConvert.DeserializeObject<RootObject>(json);
After reading a number of other similar answers, it is still throwing this error:
The best overloaded method match for 'Newtonsoft.Json.JsonConvert.DeserializeObject<RootObject>(string)' has some invalid arguments
Input json that is used in Postman for post:
{ "data": [
{"zipcode":"56033","line1":"610 4TH ST","city":"FROST","state":"MN","cid":"1770"},
{"zipcode":"56033","line1":"45375 30TH ST","city":"FROST","state":"MN","cid":"1771"},
{"zipcode":"56033","line1":"115 4TH ST","city":"FROST","state":"MN","cid":"1772"}
]}
The poco classes were created using: http://json2csharp.com .
public class Datum
{
public string zipcode { get; set; }
public string line1 { get; set; }
public string city { get; set; }
public string state { get; set; }
public string cid { get; set; }
}
public class RootObject
{
public List<Datum> data { get; set; }
}
Here is what I see when I debug the api:
{{
"data": [
{
"zipcode": "56032-0056",
"line1": "208 MAIN BOX 56",
"city": "FREEBORN",
"state": "MN",
"cid": "1732"
},
{
"zipcode": "56033",
"line1": "610 4TH ST",
"city": "FROST",
"state": "MN",
"cid": "1770"
},
{
"zipcode": "56033",
"line1": "45375 30TH ST",
"city": "FROST",
"state": "MN",
"cid": "1771"
},
{
"zipcode": "56033",
"line1": "115 4TH ST",
"city": "FROST",
"state": "MN",
"cid": "1772"
},
{
"zipcode": "56033",
"line1": "E 4TH ST",
"city": "FROST",
"state": "MN",
"cid": "1773"
}
]
}}
Not sure why webapi is adding an extra set of curly braces or how to prevent them.
Anyone see what I am missing?
jsonprobably is what OP wrote as "Input json"json, you don't show it in the code.jsondeclared? Maybe it's not actually declared as a string.