问题
If I have a JObject, which contains the property "Fields".
How do I pull out the contents of this property to an object[] with deserialized elements?
It seems like no matter what I do, I only get arrays of other JObjects.
myJObject["Fields"] {
"$type": "System.Object[], mscorlib",
"$values": [
123,
"hello"
]
}
In this case, I want to get an object array containing a long 123 and the string "hello".
回答1:
Use ToObject():
var array = myJObject["Fields"].ToObject<object[]>();
Debug.Assert(array[0].Equals(123L)); // No assert
Debug.Assert(array[1].Equals("hello")); // No assert
来源:https://stackoverflow.com/questions/29531917/json-net-deserializing-contents-of-a-jobject