反序列化JSON并从数据中获取特定行,在c#中

时间:2015-02-20 11:36:26

标签: c# json parsing deserialization

我试图获得一个特定的行,它是来自这个JSON API的元素。

API的链接是这样的: https://btc-e.com/api/3/info/

这就是它将会回归:

{
    "server_time": 1424431698,
    "pairs": {
        "btc_usd": {
            "decimal_places": 3,
            "min_price": 0.1,
            "max_price": 3200,
            "min_amount": 0.01,
            "hidden": 0,
            "fee": 0.2
        },
        "btc_rur": {
            "decimal_places": 5,
            "min_price": 1,
            "max_price": 96000,
            "min_amount": 0.01,
            "hidden": 0,
            "fee": 0.2
        },
        "btc_eur": {
            "decimal_places": 5,
            "min_price": 0.1,
            "max_price": 3200,
            "min_amount": 0.01,
            "hidden": 0,
            "fee": 0.2
        },
        "btc_cnh": {
            "decimal_places": 2,
            "min_price": 1,
            "max_price": 15000,
            "min_amount": 0.01,
            "hidden": 0,
            "fee": 0.2
        },
        "btc_gbp": {
            "decimal_places": 5,
            "min_price": 0.1,
            "max_price": 1600,
            "min_amount": 0.01,
            "hidden": 0,
            "fee": 0.2
        },
        "ltc_btc": {
            "decimal_places": 5,
            "min_price": 0.0001,
            "max_price": 10,
            "min_amount": 0.1,
            "hidden": 0,
            "fee": 0.2
        },
        "ltc_usd": {
            "decimal_places": 6,
            "min_price": 0.0001,
            "max_price": 200,
            "min_amount": 0.1,
            "hidden": 0,
            "fee": 0.2
        },
        "ltc_rur": {
            "decimal_places": 5,
            "min_price": 0.1,
            "max_price": 6000,
            "min_amount": 0.1,
            "hidden": 0,
            "fee": 0.2
        },
        "ltc_eur": {
            "decimal_places": 3,
            "min_price": 0.0001,
            "max_price": 200,
            "min_amount": 0.1,
            "hidden": 0,
            "fee": 0.2
        },
        "ltc_cnh": {
            "decimal_places": 2,
            "min_price": 0.1,
            "max_price": 1000,
            "min_amount": 0.1,
            "hidden": 0,
            "fee": 0.2
        },
        "ltc_gbp": {
            "decimal_places": 3,
            "min_price": 0.001,
            "max_price": 100,
            "min_amount": 0.1,
            "hidden": 0,
            "fee": 0.2
        },
        "nmc_btc": {
            "decimal_places": 5,
            "min_price": 0.0001,
            "max_price": 10,
            "min_amount": 0.1,
            "hidden": 0,
            "fee": 0.2
        },
        "nmc_usd": {
            "decimal_places": 3,
            "min_price": 0.001,
            "max_price": 100,
            "min_amount": 0.1,
            "hidden": 0,
            "fee": 0.2
        },
        "nvc_btc": {
            "decimal_places": 5,
            "min_price": 0.0001,
            "max_price": 10,
            "min_amount": 0.1,
            "hidden": 0,
            "fee": 0.2
        },
        "nvc_usd": {
            "decimal_places": 3,
            "min_price": 0.001,
            "max_price": 100,
            "min_amount": 0.1,
            "hidden": 0,
            "fee": 0.2
        },
        "usd_rur": {
            "decimal_places": 5,
            "min_price": 25,
            "max_price": 150,
            "min_amount": 0.1,
            "hidden": 0,
            "fee": 0.2
        },
        "eur_usd": {
            "decimal_places": 5,
            "min_price": 0.5,
            "max_price": 2,
            "min_amount": 0.1,
            "hidden": 0,
            "fee": 0.2
        },
        "eur_rur": {
            "decimal_places": 5,
            "min_price": 30,
            "max_price": 200,
            "min_amount": 0.1,
            "hidden": 0,
            "fee": 0.2
        },
        "usd_cnh": {
            "decimal_places": 4,
            "min_price": 1,
            "max_price": 15,
            "min_amount": 0.1,
            "hidden": 0,
            "fee": 0.2
        },
        "gbp_usd": {
            "decimal_places": 4,
            "min_price": 0.1,
            "max_price": 3,
            "min_amount": 0.1,
            "hidden": 0,
            "fee": 0.2
        },
        "ppc_btc": {
            "decimal_places": 5,
            "min_price": 0.0001,
            "max_price": 10,
            "min_amount": 0.1,
            "hidden": 0,
            "fee": 0.2
        },
        "ppc_usd": {
            "decimal_places": 3,
            "min_price": 0.001,
            "max_price": 100,
            "min_amount": 0.1,
            "hidden": 0,
            "fee": 0.2
        }
    }
}

我想要的只是解析末尾的“ltc_btc”行,具体而言我想将所有元素都放入变量中,所以“decimal_places”,“min_price”等等,所有这些都在{ }括号,但仅适用于“ltc_btc”行。

所以只有这个请:

{"decimal_places":5,"min_price":0.1,"max_price":1600,"min_amount":0.01,"hidden":0,"fee":0.2},"ltc_btc":

如何从该行获取变量?我正在使用JSON.Net。

1 个答案:

答案 0 :(得分:0)

你做不到。您必须反序列化所有JSON,然后从反序列化对象中检索该行。