Create class with only fields you need and then deserialize json
public class YourTwoField
{
[JsonProperty("field1")]
public string FieldOne { get; set; }
[JsonProperty("field2")]
public string FieldTwo { get; set; }
}
var myfields = Newtonsoft.Json.JsonConvert.DeserializeObject<YourTwoField>(yourJsonString);
// use values
myfields.FieldOne
Update on comments:
Your problem was that You didn't provide enough information at the beginning.
Fields you required is in the bottom level of JSON hierarchy.
- Copy your json result to the clipboard
- In Visual Studio open empty file
- Then
Edit
-> Paste Special
-> Paste JSON as Classes
Now get all JSON schema as classes where I think will be generated some RootObject
, then
var root = Newtonsoft.Json.JsonConvert.DeserializeObject<RootObject>(yourJsonString);
//Then your can brows to the values you want
root.results.First().openfda.generic_name
root.results.First().openfda.brand_name
Or loop all results
foreach(var result in root.results)
{
result.openfda.generic_name;
result.openfda.brand_name;
}