c#json进行阵列调试“应用程序进入中断模式"; [英] c# json to array debugging "application went to break mode"

查看:100
本文介绍了c#json进行阵列调试“应用程序进入中断模式";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将json转换为数组,但是在尝试调试模式时出现应用程序进入中断模式",如果尝试运行该程序,程序将冻结.

I wanted to convert a json into an array but I get "application went to break mode" when I try debugging mode and the program just freezes down if I try to run it.

我用的答案是 将json转换为C#数组吗? 但是出了点问题.

I used the answer of Convert json to a C# array? but something went wrong.

您能帮我找到错误原因吗?

Could you help me to find the cause of the error?

{
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();
    }
}

}

我添加了参考,任何想法我为什么都能获得

I added the reference, any idea why can I get the

未处理的异常:System.IO.FileNotFoundException:无法加载文件或程序集"System.Web.Extensions,版本= 4.0.0.0,区域性=中性,PublicKeyToken = 31bf3856ad364e35".该系统找不到指定的文件. 在Eve_console_app.Program.Main(String [] args)

Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified. at Eve_console_app.Program.Main(String[] args)

错误?

推荐答案

使用此代码并确保引用System.Runtime.Serialization dll

Use this code and make sure to reference System.Runtime.Serialization dll

using System;
using System.Collections.Generic;
using System.Runtime.Serialization.Json;
namespace StackOverFlow
{
    class Program
    {
        static void Main(string[] args)
        {
            var request = System.Net.WebRequest.Create("https://esi.tech.ccp.is/latest/markets/10000002/history/?datasource=tranquility&type_id=42") as System.Net.HttpWebRequest;
            request.Method = "GET";
            request.ContentLength = 0;
            using (var response = request.GetResponse() as System.Net.HttpWebResponse)
            {
                if (response.StatusCode != System.Net.HttpStatusCode.OK)
                {
                    throw new Exception(response.StatusCode + "\t" + response.StatusDescription);
                }

                DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(List<MarketHistory>));
                var result = jsonSerializer.ReadObject(response.GetResponseStream()) as List<MarketHistory>;
            }
            Console.ReadLine();
        }
    }

    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 average { get; set; }
        public string lowest { get; set; }
    }
}

这篇关于c#json进行阵列调试“应用程序进入中断模式";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆