I have some JSON data that look like this:
{ "response":{ "_token":"StringValue", "code":"OK", "user":{ "userid":"2630944", "firstname":"John", "lastname":"Doe", "reference":"999999999", "guid":"StringValue", "domainid":"99999", "username":"jdoe", "email":" jdoe@jdoe.edu ", "passwordquestion":"", "flags":"0", "lastlogindate":"2013-02-05T17:54:06.31Z", "creationdate":"2011-04-15T14:40:07.22Z", "version":"3753", "data":{ "aliasname":{ "$value":"John Doe" }, "smsaddress":{ "$value":" 5555555555@messaging.sprintpcs.com " }, "blti":{ "hideemail":"false", "hidefullname":"false" }, "notify":{ "grades":{ "$value":"0" }, "messages":{ "$value":"1" } }, "beta_component_courseplanexpress_1":{ "$value":"true" } } } }
I am using C # with JSON.NET for data analysis. I was able to get data using this algorithm:
User MyUser = new User(); JToken data = JObject.Parse(json); MyUser.FirstName = (string) data.SelectToken("response.user.firstname");
The problem is the data field. This field is mainly based on user preferences, and data is only inserted if it is being used. Fields are all customizable, and developers can insert as many as they want, without restrictions. In fact, this is all free form data. Also, as you noticed, they can be nested very far with the data.
I tried to run:
MyUser.Data = JsonConvert.DeserializeObject<List<JToken>>((string) data.SelectToken("response.user.data");
which does not work.
How are you going to convert it for use in a C # object?
claydiffrient
source share