如何使用 c# 使用 HttpWebResponse 制作 api

问题描述

我是 C# 新手 如何将下面的 json 反序列化为 .Net 对象

 
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,"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();

请问我怎么做,出现错误:

无法将当前 JSON 对象(例如 {"name":"value"})反序列化为类型“System.Collections.Generic.List`1[MyT]”,因为该类型需要一个 JSON 数组(例如 [1,2,3]) 以正确反序列化。 要修复此错误,请将 JSON 更改为 JSON 数组(例如 [1,3])或更改反序列化类型,使其成为普通的 .NET 类型(例如,不是像整数这样的原始类型,而不是像这样的集合类型)可以从 JSON 对象反序列化的数组或列表)。还可以将 JsonObjectAttribute 添加到类型以强制它从 JSON 对象反序列化。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...