-2

I have a API response has a structure like shown below. How can I get the values from this Json string?

[
{
    "id": xxx,
    "profileId": xxx,
    "recipientId": xxx,
    "creationTime": "xxxx",
    "modificationTime": "xxxx",
    "active": true,
    "eligible": true,
    "balances": [
        {
            "balanceType": "AVAILABLE",
            "currency": "EUR",
            "amount": {
                "value": 55555,
                "currency": "EUR"
            },
            "reservedAmount": {
                "value": 0,
                "currency": "EUR"
            },
            "bankDetails": {
                "id": xxx,
                "currency": "EUR",
                "bankCode": "code",
                "accountNumber": "account number",
                "swift": "swift",
                "iban": "iban",
                "bankName": "bankName",
                "accountHolderName": "accountHolderName",
                "bankAddress": {
                    "addressFirstLine": "bankAddress",
                    "postCode": "xxxxx",
                    "city": "xxxxx",
                    "country": "xxxxx",
                    "stateCode": null
                }
            }
        }
    ]
}

]

I am using The below extension method to get data for some other API's I have integrated in my system. This works fine for the other API's I have integrated.

 public static string GetJsonField(RestSharp.IRestResponse value, string res)
    {
        Newtonsoft.Json.Linq.JObject json = Newtonsoft.Json.Linq.JObject.Parse(value.Content);
        res = json.GetValue(res).ToString();
        return res;
    }

Thanks in advance

Taco2
  • 429
  • 1
  • 6
  • 18
  • I think [this](https://stackoverflow.com/questions/17617594/how-to-get-some-values-from-a-json-string-in-c) is what you are looking for. – bthn Apr 22 '19 at 20:26

1 Answers1

-1

Copy that Json in json2csharp.com, it will give you the classes that you will need to convert the Json in a c# object.

Then just use var myJson = JsonConverter.deserialize(Json) ;

And you can access to the Json properties as you do with any other class

Bloodday
  • 303
  • 1
  • 15