Method for C to convert json format into object and replace key
- 2021-07-01 08:08:01
- OfStack
This article illustrates the method of C # converting json format to object and replacing key. Share it for your reference. The specific analysis is as follows:
Because it is a non-standard serialization object type, you can't implement it through the standard deserialization class. You need to customize a serialization class or simply customize a method to parse Json data directly. The parsed data is stored by Dictionary.
string str = "{\"name\": \" Zhen Ti \",\"2012-05-04 14:59\": \"5724\"}";
JavaScriptObject obj = JavaScriptConvert.DeserializeObject(str) as JavaScriptObject;
foreach (KeyValuePair<string, object> k in obj)
{
Console.WriteLine("Key : {0} Value : {1}", k.Key, k.Value);
}
The output is as follows:
Key: name Value: Zhen Ti
Key: 2012-05-04 14:59 Value: 5724
I hope this article is helpful to everyone's C # programming.