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

Mikkel Nielsen
  • 792
  • 2
  • 13
  • 36

2 Answers2

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);
L.B
  • 114,136
  • 19
  • 178
  • 224
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.

yamen
  • 15,390
  • 3
  • 42
  • 52