2016-06-17 4 views
-2

I have this json 그리고 난 내가 예를 들어 각 개체의 값을 얻을 수를 직렬화하는 :JSON 문자열 직렬화 C#을

"icon_url": "-9a81dlWLwJ2UUGcVs_nsVtzdOEdtWwKGZZLQHTxDZ7I56KU0Zwwo4NUX4oFJZEHLbXH5ApeO4YmlhxYQknCRvCo04DEVlxkKgpouLWzKjhzw8zFdC5K092kl5SClMj3PLXFhGpC_Pp8j-3I4IG7i1Hn_UI-Nmj3ItDGe1BoN1mCr1G4xL_vhMS8tcmcn3JhuihwsHvbzQv3309k3tBw8A", 

문제는 내가 내가 역 직렬화 수 있도록 필요한 클래스 (들)을 할 수있다 json 문자열에는 중첩 된 객체가 있기 때문에 json.

+0

오른쪽으로 중첩 된 개체를 역 직렬화 할 수 있습니다 :

이 올바르게 작동하는 것처럼
public class InventoryItem { public string id { get; set; } public string classid { get; set; } public string instanceid { get; set; } public string amount { get; set; } public int pos { get; set; } } public class AppData { public string def_index { get; set; } public int? is_itemset_name { get; set; } public int? limited { get; set; } } public class Description { public string type { get; set; } public string value { get; set; } public string color { get; set; } public AppData app_data { get; set; } } public class Action { public string name { get; set; } public string link { get; set; } } public class Tag { public string internal_name { get; set; } public string name { get; set; } public string category { get; set; } public string category_name { get; set; } public string color { get; set; } } public class RgDescription { public string appid { get; set; } public string classid { get; set; } public string instanceid { get; set; } public string icon_url { get; set; } public string icon_url_large { get; set; } public string icon_drag_url { get; set; } public string name { get; set; } public string market_hash_name { get; set; } public string market_name { get; set; } public string name_color { get; set; } public string background_color { get; set; } public string type { get; set; } public int tradable { get; set; } public int marketable { get; set; } public int commodity { get; set; } public string market_tradable_restriction { get; set; } public List<Description> descriptions { get; set; } public List<Action> actions { get; set; } public List<Action> market_actions { get; set; } public List<Tag> tags { get; set; } } public class RootObject { public bool success { get; set; } public IDictionary<string, InventoryItem> rgInventory { get; set; } public List<object> rgCurrency { get; set; } public IDictionary<string, RgDescription> rgDescriptions { get; set; } public bool more { get; set; } public bool more_start { get; set; } } 

, 당신은 직렬화와 같은 코드로 직렬화 할 수 있습니다 수업. 너 뭐 해봤 니? –

+0

[내 수업] (http://pastebin.com/8WXZihKr) JsonInv를 사용하여 비 직렬화 –

+0

모든 'icon_url' 데이터를 원하고 그들이 속한 개체에 신경 쓰지 않습니까? –

답변

1

클래스 생성에 도움이되도록 json2csharp을 사용했습니다. 일부 병합 및 청소 후,이 내가 가진 것입니다 :

var obj = JsonConvert.DeserializeObject<RootObject>(oldString); 
Console.WriteLine(obj.rgDescriptions["310776560_302028390"].icon_url); // e.g. 
var newString = JsonConvert.SerializeObject(obj, 
    new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); 
// null value handling is optional, the above makes it a little more like the source string 
+0

[ "310776560_302028390"] 아이템을 주면 ([ "310776560_302028390"] 증기의 고유 아이템이기 때문에) 해결책을 찾을 수있어서 매우 감사드립니다. "310776560_302028390"을 생성해야했습니다. "this from string item = obj.rgInventory ["6596605087 "] .classid +"_ "+ obj.rgInventory ["6596605087 "]. instanceid;'어쨌든, 대단히 감사합니다! –

+0

하하 ... json2csharp ... 당신은 모든 "public class _invalid_type ..." –