Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用C语言反序列化JSON文件#_C#_Json.net - Fatal编程技术网

C# 使用C语言反序列化JSON文件#

C# 使用C语言反序列化JSON文件#,c#,json.net,C#,Json.net,我正在创建一个Steam应用程序(用于Steam平台),我需要反序列化一个JSON文件 { "response": { "success": 1, "current_time": 1401302092, "raw_usd_value": 0.245, "usd_currency": "metal", "usd_currency_index": 5002, "items": { "A Brush with Death": {

我正在创建一个Steam应用程序(用于Steam平台),我需要反序列化一个JSON文件

{
"response": {
    "success": 1,
    "current_time": 1401302092,
    "raw_usd_value": 0.245,
    "usd_currency": "metal",
    "usd_currency_index": 5002,
    "items": {
        "A Brush with Death": {
            "defindex": [
                30186
            ],
            "prices": {
                "6": {
                    "Tradable": {
                        "Craftable": [
                            {
                                "currency": "metal",
                                "value": 4,
                                "last_update": 1398990171,
                                "difference": 0.17
                            }
                        ]
                    }
                }
            }
        },
...
我只需要得到Defindex和value。已经反序列化了一些简单的JSON文件,但我认为这个更复杂


对于那些想知道的人,我正在使用BackpackTF中的API…

使用nuget包调用程序Newtonsoft.Json.5.0.8。它位于nuget存储库中。

使用nuget包调用程序Newtonsoft.Json.5.0.8。它位于nuget存储库中。

使用nuget包调用程序Newtonsoft.Json.5.0.8。它位于nuget存储库中。

使用nuget包调用程序Newtonsoft.Json.5.0.8。它位于nuget存储库中。

使用NewtonSoft.Json,然后您可以按如下方式使用它来获取数据

    dynamic json = JsonConvert.DeserializeObject(<yourstring>);
    string currency = json.response.usd_currency;  // "metal"
DynamicJSON=JsonConvert.DeserializeObject();
字符串currency=json.response.usd_currency;//“金属”

使用NewtonSoft.Json,然后您可以按如下方式使用它来获取数据

    dynamic json = JsonConvert.DeserializeObject(<yourstring>);
    string currency = json.response.usd_currency;  // "metal"
DynamicJSON=JsonConvert.DeserializeObject();
字符串currency=json.response.usd_currency;//“金属”

使用NewtonSoft.Json,然后您可以按如下方式使用它来获取数据

    dynamic json = JsonConvert.DeserializeObject(<yourstring>);
    string currency = json.response.usd_currency;  // "metal"
DynamicJSON=JsonConvert.DeserializeObject();
字符串currency=json.response.usd_currency;//“金属”

使用NewtonSoft.Json,然后您可以按如下方式使用它来获取数据

    dynamic json = JsonConvert.DeserializeObject(<yourstring>);
    string currency = json.response.usd_currency;  // "metal"
DynamicJSON=JsonConvert.DeserializeObject();
字符串currency=json.response.usd_currency;//“金属”

通常,您要做的是确保您拥有有效的JSON(用于此),然后使用获取C#类定义,然后执行以下操作:

MyClass myobject=JsonConvert.DeserializeObject<MyClass>(json);
MyClass myobject=JsonConvert.DeserializeObject(json); (我们假设MyClass基于您从JSON2Charp获得的内容)


然后通过传统的C#点符号访问所需的值。

通常,您要做的是确保您拥有有效的JSON(用于此),然后使用获得C#类定义,然后执行以下操作:

MyClass myobject=JsonConvert.DeserializeObject<MyClass>(json);
MyClass myobject=JsonConvert.DeserializeObject(json); (我们假设MyClass基于您从JSON2Charp获得的内容)


然后通过传统的C#点符号访问所需的值。

通常,您要做的是确保您拥有有效的JSON(用于此),然后使用获得C#类定义,然后执行以下操作:

MyClass myobject=JsonConvert.DeserializeObject<MyClass>(json);
MyClass myobject=JsonConvert.DeserializeObject(json); (我们假设MyClass基于您从JSON2Charp获得的内容)


然后通过传统的C#点符号访问所需的值。

通常,您要做的是确保您拥有有效的JSON(用于此),然后使用获得C#类定义,然后执行以下操作:

MyClass myobject=JsonConvert.DeserializeObject<MyClass>(json);
MyClass myobject=JsonConvert.DeserializeObject(json); (我们假设MyClass基于您从JSON2Charp获得的内容)


然后通过传统的C#dot符号访问所需的值。

这行代码将json作为字符串,并将其转换为根对象

RootObject obj = JsonConvert.DeserializeObject<RootObject>(jsonString);
rootobjectobj=JsonConvert.DeserializeObject(jsonString);
您提供的Json有点缺陷,但我猜您要查找的c#对象的结构与此相近:

public class Craftable
{
    public string currency { get; set; }
    public int value { get; set; }
    public int last_update { get; set; }
    public double difference { get; set; }
}

public class Tradable
{
    public List<Craftable> Craftable { get; set; }
}

public class Prices
{
    public Tradable Tradable{ get; set; }
}

public class Items
{
    public List<int> defindex { get; set; }
    public Prices prices { get; set; }
}

public class Response
{
    public int success { get; set; }
    public int current_time { get; set; }
    public double raw_usd_value { get; set; }
    public string usd_currency { get; set; }
    public int usd_currency_index { get; set; }
    public Items items { get; set; }
}

public class RootObject
{
    public Response response { get; set; }
}
公共类可手工制作
{
公共字符串货币{get;set;}
公共int值{get;set;}
public int last_update{get;set;}
公共双差{get;set;}
}
公共阶级可交易
{
公共列表可手工制作{get;set;}
}
公共类价格
{
公共可交易{get;set;}
}
公共类项目
{
公共列表defindex{get;set;}
公共价格{get;set;}
}
公众课堂反应
{
公共int成功{get;set;}
公共int当前_时间{get;set;}
公共双原始值{get;set;}
公共字符串usd_货币{get;set;}
公共整数美元货币指数{get;set;}
公共项目{get;set;}
}
公共类根对象
{
公共响应{get;set;}
}

这行代码将json作为字符串,并将其转换为根对象

RootObject obj = JsonConvert.DeserializeObject<RootObject>(jsonString);
rootobjectobj=JsonConvert.DeserializeObject(jsonString);
您提供的Json有点缺陷,但我猜您要查找的c#对象的结构与此相近:

public class Craftable
{
    public string currency { get; set; }
    public int value { get; set; }
    public int last_update { get; set; }
    public double difference { get; set; }
}

public class Tradable
{
    public List<Craftable> Craftable { get; set; }
}

public class Prices
{
    public Tradable Tradable{ get; set; }
}

public class Items
{
    public List<int> defindex { get; set; }
    public Prices prices { get; set; }
}

public class Response
{
    public int success { get; set; }
    public int current_time { get; set; }
    public double raw_usd_value { get; set; }
    public string usd_currency { get; set; }
    public int usd_currency_index { get; set; }
    public Items items { get; set; }
}

public class RootObject
{
    public Response response { get; set; }
}
公共类可手工制作
{
公共字符串货币{get;set;}
公共int值{get;set;}
public int last_update{get;set;}
公共双差{get;set;}
}
公共阶级可交易
{
公共列表可手工制作{get;set;}
}
公共类价格
{
公共可交易{get;set;}
}
公共类项目
{
公共列表defindex{get;set;}
公共价格{get;set;}
}
公众课堂反应
{
公共int成功{get;set;}
公共int当前_时间{get;set;}
公共双原始值{get;set;}
公共字符串usd_货币{get;set;}
公共整数美元货币指数{get;set;}
公共项目{get;set;}
}
公共类根对象
{
公共响应{get;set;}
}

这行代码将json作为字符串,并将其转换为根对象

RootObject obj = JsonConvert.DeserializeObject<RootObject>(jsonString);
rootobjectobj=JsonConvert.DeserializeObject(jsonString);
您提供的Json有点缺陷,但我猜您要查找的c#对象的结构与此相近:

public class Craftable
{
    public string currency { get; set; }
    public int value { get; set; }
    public int last_update { get; set; }
    public double difference { get; set; }
}

public class Tradable
{
    public List<Craftable> Craftable { get; set; }
}

public class Prices
{
    public Tradable Tradable{ get; set; }
}

public class Items
{
    public List<int> defindex { get; set; }
    public Prices prices { get; set; }
}

public class Response
{
    public int success { get; set; }
    public int current_time { get; set; }
    public double raw_usd_value { get; set; }
    public string usd_currency { get; set; }
    public int usd_currency_index { get; set; }
    public Items items { get; set; }
}

public class RootObject
{
    public Response response { get; set; }
}
公共类可手工制作
{
公共字符串货币{get;set;}
公共int值{get;set;}
public int last_update{get;set;}
公共双差{get;set;}
}
公共阶级可交易
{
公共列表可手工制作{get;set;}
}
公共类价格
{
公共可交易{get;set;}
}
公共类项目
{
公共列表defindex{get;set;}
公共价格