我想将 json 转换为数组,但当我尝试调试模式时,我得到“应用程序进入中断模式”,并且如果我尝试运行它,程序就会冻结。
我用的答案是将 json 转换为 C# 数组? https://stackoverflow.com/questions/9586585/convert-json-to-a-c-sharp-array但出了点问题。
你能帮我找出错误的原因吗?
{
public class MarketHistory
{
public string Date { get; set; }
public string Order_Count { get; set; }
public string Volume { get; set; }
public string Highest { get; set; }
public string Avarage { get; set; }
public string Lowest { get; set; }
}
class Program
{
public static string DownloadString(string address)
{
WebClient client = new WebClient();
string reply = client.DownloadString(address);
return reply;
}
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
string url = "https://esi.tech.ccp.is/latest/markets/10000002/history/?datasource=tranquility&type_id=42";
var json = DownloadString(url);
JavaScriptSerializer js = new JavaScriptSerializer();
MarketHistory[] marketHistories = js.Deserialize<MarketHistory[]>(json);
Console.ReadKey();
}
}
}
json:
[
{
"date": "2016-11-01",
"order_count": 24,
"volume": 275,
"highest": 28.17,
"average": 28.15,
"lowest": 28
},
第一个修复:
{
public class MarketHistory
{
public string date { get; set; }
public string order_count { get; set; }
public string volume { get; set; }
public string highest { get; set; }
public string avarage { get; set; }
public string lowest { get; set; }
}
class Program
{
public static string DownloadString(string address)
{
WebClient client = new WebClient();
string reply = client.DownloadString(address);
return reply;
}
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
string url = "https://esi.tech.ccp.is/latest/markets/10000002/history/?datasource=tranquility&type_id=42";
var json = DownloadString(url);
JavaScriptSerializer js = new JavaScriptSerializer();
MarketHistory[] marketHistories = js.Deserialize<MarketHistory[]>(json);
Console.ReadKey();
}
}
}
我添加了参考,知道为什么我可以获得
未处理的异常:System.IO.FileNotFoundException:无法加载文件或程序集“System.Web.Extensions,版本= 4.0.0.0,文化=中性,PublicKeyToken = 31bf3856ad364e35”。该系统找不到指定的文件。
在 Eve_console_app.Program.Main(String[] args)
error?