问题
Im trying to read some json data using RestSharp.
But im having some problems reading json objects. I have this respons:
expand: "html",
self: "<url>/INCIDENT-447",
key: "INCIDENT-447",
fields: {
customfield_11414: {
name: "Corrective Measures",
type: "com.atlassian.jira.plugin.system.customfieldtypes:textarea"
},
summary: {
name: "summary",
type: "java.lang.String",
value: "BLA BLA BLA"
},
I need to create a object with Property's summery and customfield_11414 But i only need the value of them. Not the entire JSON object
回答1:
You can use Json.Net and dynamic
keyword together
dynamic dynObj = JsonConvert.DeserializeObject(json);
Console.WriteLine(dynObj.fields.customfield_11414.name + " " +
dynObj.fields.summary.value);
回答2:
You have a few options. One is to not try and deserialise everything, but rather just make the JSON available for LINQ/XPATH style searching. This is using Json.NET:
var json = " ... "; // your json here
var o = JObject.Parse(json);
var summary = o["summary"];
var customfield_11414 = o.SelectToken("customfield_11414");
These return everything as JToken
, which you could cast if needed, or further parse.
来源:https://stackoverflow.com/questions/10136049/deserialize-json-object-to-c-sharp-object