C#不能读取和跨preT网络API / JSON [英] C# can't read and interpret web API/JSON

查看:174
本文介绍了C#不能读取和跨preT网络API / JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里的第一个问题,可能是因为我发现previous问题和放大器的负载;这里的答案:)我只是一个爱好程序员,我只知道的基本知识,但我就是喜欢编程:D
我一直在破解我的头在2天以下的问题,现在,我想知道,如果你们能帮助我吗?

My first question here, probably because I found loads of previous questions & answers here :) I'm just a hobby programmer, I know only the basics, but I just love programming :D I've been cracking my head over the following problem for 2 days now, and I wonder if you guys could help me?

我在编程GUI显示器为我的比特币/ altcoin矿工(具体为ccminer NVIDIA矿工),我想一个矿工能够跳上最赚钱的硬币,如果我已经为它配置。
得到这些数字的最简单的方法是低谷众多网站的API,如这个。所以你可以看到,有很多的API(会一直挂多了,但不许尚未),但他们都不似乎工作。

I'm programming a GUI monitor for my bitcoin/altcoin miners (specifically, ccminer for NVIDIA miners), and I want a miner to be able to jump on the most profitable coin if I have set a config for it. The easiest way to get these numbers would be trough the numerous web API's, like this and this. So you can see, there are numerous API's (would've linked more, but not allowed yet), but none of them seems to work.

这是code我到目前为止有:

This is the code I have so far:

class Api
{
    public static List<Coins> _download_serialized_json_data(string address)
    {
        List<Coins> coinList = new List<Coins>();
        using (WebClient web = new WebClient())
        {
            string jsonData = web.DownloadString(address);
            JObject json = JObject.Parse(jsonData);


            for (int i = 1; i <= 10; i++)
            {
                Coins c = new Coins();
                c.tag = json["coins"][i]["tag"];

                coinList.Add(c);
            }
        }

        return coinList;
    }
}

public class Coins
{
    public string tag { get; set; }
}

ATM,我使用调试模式只是为了看一下里面的物体是什么,但是当我尝试使用我的方法在此API(或任何其他具有相应的元素),但在

ATM, I'm using the debug mode just to look at what's inside the objects but when I try to use my method at this api (or any other with corresponding elements) but at

c.tag = json["coins"][i]["tag"];

它的错误了。我不知道在哪里可以找到确切的错误太多,但即使当我试图JArray.Parse这是行不通的。难道我做的一个关键失误的地方?

It errors out. I don't know where to find the exact error too, but even when I'm trying JArray.Parse it just doesn't work. Am I making a crucial mistake somewhere?

提前感谢!

推荐答案

您试图做这样的事情?

Webclient wc = new Webclient();
var json = wc.DownloadString("http://www.whattomine.com/coins.json"); //your 2nd link
var coins = JsonConvert.DeserializeObject<Coins>(json);


public class Coins
{
    public Dictionary<string, Coin> coins = null;
}
public class Coin
{
    public string tag { get; set; }
    public string algorithm { get; set; }
    public double block_reward { get; set; }
    public int block_time { get; set; }
    public int last_block { get; set; }
    public double difficulty { get; set; }
    public double difficulty24 { get; set; }
    public double nethash { get; set; }
    public double exchange_rate { get; set; }
    public string market_cap { get; set; }
    public double volume { get; set; }
    public int profitability { get; set; }
    public int profitability24 { get; set; }
}

这篇关于C#不能读取和跨preT网络API / JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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