0

I am new to c# How do I deserialize the json below to .Net object

 
Response (JSON):

    Success Response :
    {
        "code": "0001",
        "status": "success",
        "message": " data retrieved",
        "data": {
            "balance": {
                "Date": "2 JAnuary 1920",
                "accountNo": "123456",
                "accountName": "My account name",
                "balance": "400.0",
                " transactions ": [
                {
                "transactionDate": [1920, 1, 23],
                "amount": 0.000000,
                "createdDate": [1920, 1, 23],
                "amountIndicator": 2,
                "narration": "cash withdrawal",
                "uniqueIdentifier": "00023",
                "details": "cash withdrawal"
             }
                 ]
    }
    }
    }


    string Url = "http://postalpincode.in/api/pincode/";
    HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create(Url);
    webrequest.Method = "GET";
    webrequest.ContentType = "application/json";
    HttpWebResponse webresponse = (HttpWebResponse)webrequest.GetResponse();
    StreamReader reader = new StreamReader(webresponse.GetResponseStream(), System.Text.Encoding.GetEncoding("utf-8"));
    string readToEnd = reader.ReadToEnd();

Please how do I do it am getting error:

Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.List`1[MyT]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly. To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object.

lmoshood
  • 9
  • 2
  • 2
    "Please how do I continue", should read "How do I start" . Starting can be done by reading [How to make an HTTP POST web request](https://stackoverflow.com/questions/4015324/how-to-make-an-http-post-web-request) or by any/some/all of the links in : [Google: how to make HttpWebRequest in c#](https://www.google.com/search?q=how+to+make+HttpWebRequest+in+c%23) – Luuk Jul 11 '21 at 12:50
  • You should use HttpClient instead. That is the way to go now days. In .net core http web request uses http client under the hood anyways – Jonathan Alfaro Jul 12 '21 at 06:34

0 Answers0