0

Disclaimer: I'm fairly new to C#

I know questions on JSON have been asked to death on here but I can't find a response to my particular scenario and can't manage to apply other solutions to it.

I have a var storing a json string from a httpresponse as shown

{
    "id": "1c8d2082-05b2-4ad9-8ed5-7114648aa5cb",
    "project": "064ee1fd-ebe0-467c-8dda-b6b4058bd348",
    "iteration": "3fcc61a0-d137-4089-affd-67c032aaea8b",
    "created": "2021-10-11T08:57:17.284Z",
    "predictions": [{
            "probability": 0.613616,
            "tagId": "f47615ba-2222-4df3-8c5c-aded0a65a364",
            "tagName": "MintImp"
        }, {
            "probability": 0.3563068,
            "tagId": "17dd80a6-7419-4720-8a17-9690dc9f06fc",
            "tagName": "HandsAndNegative"
        }, {
            "probability": 0.030073652,
            "tagId": "b733e302-e9da-4dd5-94ff-4ced50c8ebe7",
            "tagName": "Marshmallow"
        }, {
            "probability": 2.5170968E-06,
            "tagId": "3746fe20-fa24-43cc-9525-e3ff7d929c48",
            "tagName": "ChocCaram"
        }, {
            "probability": 8.989376E-07,
            "tagId": "c658f321-f009-4e55-bc36-102bb2c362cf",
            "tagName": "LemonSherbert"
        }, {
            "probability": 1.5125686E-07,
            "tagId": "466e2857-36f5-4e3f-8b49-953c928592c7",
            "tagName": "MidgetGem"
        }
    ]
}


As the response contains an array within the text I can't understand how I access the array within this text. I need to access the tagName where the probability is greatest.

Any suggestions on how to extract the array from within the text?

ProgrammingLlama
  • 36,677
  • 7
  • 67
  • 86

1 Answers1

0

Firstlt, de-serialize the JSON response and then, you can use LINQ to do so.

var tagNameOfGreatestProbability = json.predictions.OrderByDescending(w => w.probability).First().tagName;
Rithik Banerjee
  • 447
  • 4
  • 16