1

I am new to c# json. I would only want to get CardTransactions array , "status": 0, and ignore the rest of the json values. May I know how to achieve with c#.

{
    "response":{
        "timeStamp":7812371,
        "totalCount":1,
        "CardTransactions":[
            {
                "transactionDate":"2021-08-16",
                "invoiceNo":"KM011782313",
                "amount":2000.00
            }
        ],
        "status":0,
        "message":"dakjalsda"
    },
    "status":null,
    "message":null
}
1
  • Are you using Newtonsoft.Json (also known as Json.NET) or System.Text.Json for deserialization? Commented Oct 21, 2021 at 10:46

1 Answer 1

2

Create a model class that looks that way

public class Response 
{
    [JsonProperty("CardTransactions")]
    public List<CardTransaction> CardTransactions { get; set; }

    [JsonProperty("status")]
    public int Status { get; set; }
}

public class Root
{
    [JsonProperty("response")]
    public Response Response { get; set; }
}

and use Newtonsoft to convert JSON to object like the following

Root response = JsonConvert.DeserializeObject<Root>(yourJson);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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.