1

I have the following JSON that is returned to me from an API call. I’m trying to just get the information from a property called "products". Once I have that into an array or list I need to look for a specific product name and then one of it’s properties.

I’ve tried a handful of different things without any luck. I’m also searching and not finding what I’m looking for in my scenario.

If I use the following, I can get the data into parseJson object but from there I don’t understand how I can pull just the "products" into an array so I can loop through them looking for a specific product and it’s value.

dynamic parseJson = JsonConvert.DeserializeObject(response.Content);

I also tried this but had no luck either.

dynamic parseJson = JsonConvert.DeserializeObject<AccurateApiResult>(response.Content);
public class AccurateApiResult 
 {
 public List<AccurateProduct> products { get; set; }
 }
public class AccurateProduct
 {
 public int id { get; set; }
 public string productType { get; set; }
 public string status { get; set; }
 public string result { get; set; }
 public bool flag { get; set; }
 }

Here is the sample data and I’m only interested in the "products" section. How can I pull just that data?

[
 {
 "resource": "ORDER",
 "id": "Y10046727",
 "created": "2022年06月28日T13:18:17Z",
 "updated": "2022年06月28日T13:18:17Z",
 "workflow": "INTERACTIVE",
 "candidate": {
 "firstName": "Marcus",
 "lastName": "Willis",
 "middleName": null,
 "suffix": null,
 "dateOfBirth": "1990年01月01日",
 "ssn": "111111111",
 "email": null,
 "phone": "240-5798551",
 "address": "3433 Lumar dr",
 "city": "Fort Washington",
 "region": "MD",
 "country": "US",
 "postalCode": "20744",
 "governmentId": {
 "country": "US",
 "type": null,
 "number": null
 },
 "aliases": [],
 "educations": [
 {
 "school": "Test University",
 "country": "US",
 "region": "CA",
 "city": "Irvine",
 "degree": null,
 "major": null,
 "startDate": null,
 "endDate": null,
 "graduated": false,
 "graduationDate": null,
 "presentlyEnrolled": false
 }
 ],
 "prevEmployed": null,
 "employments": [],
 "convicted": null,
 "convictions": null,
 "references": [],
 "addressHistory": []
 },
 "completed": "2022年07月07日T01:59:13Z",
 "supportReferenceId": "Y10046727",
 "status": "COMPLETE",
 "result": "Meets Requirements",
 "products": [
 {
 "id": 66134505,
 "productType": "AELS",
 "status": "COMPLETE",
 "result": "NOT APPLICABLE",
 "flag": false
 },
 {
 "id": 66134506,
 "productType": "ADJ",
 "status": "COMPLETE",
 "result": "NOT APPLICABLE",
 "flag": false
 },
 {
 "id": 66134508,
 "productType": "MOV",
 "status": "COMPLETE",
 "result": "Invalid SSN",
 "flag": false
 },
 {
 "id": 66144583,
 "productType": "MVR",
 "status": "COMPLETE",
 "result": "NOT APPLICABLE",
 "flag": false
 },
 {
 "id": 66144584,
 "productType": "F/M",
 "status": "COMPLETE",
 "result": "NO RECORD FOUND",
 "flag": false
 },
 {
 "id": 66144587,
 "productType": "EDU",
 "status": "COMPLETE",
 "result": "NOT APPLICABLE",
 "flag": false
 },
 {
 "id": 66144588,
 "productType": "DL5D",
 "status": "COMPLETE",
 "result": "Negative",
 "flag": false
 }
 ],
 "percentageComplete": 0,
 "candidateInfoChanged": false,
 "searchId": 66134503,
 "subjectId": 10121219,
 "requestor": "[email protected]"
 }
asked Jul 21, 2022 at 21:14

1 Answer 1

1

you can try this code

var parsedJsonProducts = (JArray) JArray.Parse(response.Content)[0]["products"];
List<AccurateProduct> products = parsedJsonProducts.ToObject<List<AccurateProduct>>();
answered Jul 21, 2022 at 22:07
Sign up to request clarification or add additional context in comments.

1 Comment

OMG Thanks! I came close in some of the stuff I tried but was missing the .ToObject<> piece of it. Spent hours trying to figure this one out. Definitely adding this to my notes.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.