2

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

2 Answers 2

10

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);
Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.