我的ASP.Net应用程序中有一个方法如下:
Method1<T>(String inputString)
{
return JsonConvert.DeserializeObject<T>(inputString);
}
I pass stringified objects to Method1
, and one of them is a stringified version of this object:
obj1: {
a: ...
b: [...]
}
ie. obj1
is an object that has an array as a property. Now, as is, JsonConvert.DeserializeObject<T>(inputString)
won't parse the array part of this object. I learned from this post that I could make this work if type1
were the type of obj1
and I did JsonConvert.DeserializeObject<type1>(inputString)
. The problem is that I'll be passing stringified versions of a variety of different types of objects to Method1
, so I don't know how else to do it than with <T>
.
有谁知道我该怎么办?
Newtonsoft.Json.Linq
api is great for this kind of scenario. You can parse your json into an abstractJToken
object, and look at the token type to determine how to extract your array.