C#的Json - 到 - 阵列 [英] C# Json - to - Array
问题描述
所以,我有以下的json code:
So I have the following json code:
{
"users":[
{
"username":"Deeside",
"user_id":750038708,
"recent_gifts":[
],
"class_id":2,
"bonus":{
"spy_defense":27000,
"plunder":172793313,
"attack":230400,
"defense":153600,
"spy_attack":27000
},
"superpower_expire_date":null,
"avatar_id":2,
"avatar_type":1,
"cost":38602761523
},
{
"username":"mac78",
"user_id":515216476,
"recent_gifts":[
],
"class_id":2,
"bonus":{
"spy_defense":0,
"plunder":172793313,
"attack":505800,
"defense":336600,
"spy_attack":0
},
"superpower_expire_date":null,
"avatar_id":2,
"avatar_type":2,
"cost":38602761523
},
{
"username":"divie",
"user_id":750047259,
"recent_gifts":[
],
"class_id":3,
"bonus":{
"spy_defense":62100,
"plunder":172793313,
"attack":161520,
"defense":108720,
"spy_attack":54000
},
"superpower_expire_date":null,
"avatar_id":3,
"avatar_type":1,
"cost":38602761512
},
{
"username":"xOkSxGoDoFRaNDoM",
"user_id":78983234,
"recent_gifts":[
],
"class_id":3,
"bonus":{
"spy_defense":13500,
"plunder":172793313,
"attack":270720,
"defense":180480,
"spy_attack":13500
},
"superpower_expire_date":null,
"avatar_id":3,
"avatar_type":2,
"cost":38602761499
},
{
"username":"Polyphanies",
"user_id":11876768,
"recent_gifts":[
],
"class_id":2,
"bonus":{
"spy_defense":25650,
"plunder":172793313,
"attack":190240,
"defense":178740,
"spy_attack":5400
},
"superpower_expire_date":null,
"avatar_id":2,
"avatar_type":2,
"cost":38602761489
},
{
"username":"l___The_Aces___l",
"user_id":1152754333,
"recent_gifts":[
],
"class_id":2,
"bonus":{
"spy_defense":249300,
"plunder":172793313,
"attack":0,
"defense":0,
"spy_attack":249300
},
"superpower_expire_date":null,
"avatar_id":2,
"avatar_type":1,
"cost":38602761468
},
{
"username":"amlan",
"user_id":1018507644,
"recent_gifts":[
],
"class_id":4,
"bonus":{
"spy_defense":13500,
"plunder":172793313,
"attack":131400,
"defense":168000,
"spy_attack":5400
},
"superpower_expire_date":null,
"avatar_id":4,
"avatar_type":2,
"cost":38602761432
},
{
"username":"Astrumstar",
"user_id":1521748420,
"recent_gifts":[
],
"class_id":3,
"bonus":{
"spy_defense":4650,
"plunder":172793312,
"attack":29900,
"defense":105800,
"spy_attack":1950
},
"superpower_expire_date":null,
"avatar_id":3,
"avatar_type":2,
"cost":38602761265
},
{
"username":"bagarospo",
"user_id":2092280432,
"recent_gifts":[
],
"class_id":2,
"bonus":{
"spy_defense":13500,
"plunder":172793312,
"attack":241200,
"defense":159600,
"spy_attack":13500
},
"superpower_expire_date":null,
"avatar_id":2,
"avatar_type":1,
"cost":38602761233
},
{
"username":"zpear4",
"user_id":380966449,
"recent_gifts":[
],
"class_id":3,
"bonus":{
"spy_defense":118800,
"plunder":172793310,
"attack":41274,
"defense":40320,
"spy_attack":118800
},
"superpower_expire_date":null,
"avatar_id":3,
"avatar_type":1,
"cost":38602760949
},
{
"username":"sarrix",
"user_id":951332098,
"recent_gifts":[
],
"class_id":3,
"bonus":{
"spy_defense":150,
"plunder":172793303,
"attack":2797,
"defense":2797,
"spy_attack":150
},
"superpower_expire_date":null,
"avatar_id":3,
"avatar_type":1,
"cost":38602759327
},
{
"username":"UnsealedExpert",
"user_id":1890948836,
"recent_gifts":[
],
"class_id":2,
"bonus":{
"spy_defense":189900,
"plunder":172793295,
"attack":0,
"defense":0,
"spy_attack":189900
},
"superpower_expire_date":null,
"avatar_id":2,
"avatar_type":2,
"cost":38602757394
},
{
"username":"______llllllll______",
"user_id":783666874,
"recent_gifts":[
],
"class_id":2,
"bonus":{
"spy_defense":189000,
"plunder":172793264,
"attack":2400,
"defense":1600,
"spy_attack":189000
},
"superpower_expire_date":null,
"avatar_id":2,
"avatar_type":1,
"cost":38602750621
},
{
"username":"rjh",
"user_id":1958058960,
"recent_gifts":[
],
"class_id":3,
"bonus":{
"spy_defense":29700,
"plunder":172792651,
"attack":253800,
"defense":166200,
"spy_attack":29700
},
"superpower_expire_date":null,
"avatar_id":3,
"avatar_type":2,
"cost":38602613553
},
{
"username":"Senling",
"user_id":1957968694,
"recent_gifts":[
],
"class_id":2,
"bonus":{
"spy_defense":18900,
"plunder":172541048,
"attack":111040,
"defense":125940,
"spy_attack":10800
},
"superpower_expire_date":null,
"avatar_id":2,
"avatar_type":2,
"cost":38546404496
},
{
"username":"ee-Rie",
"user_id":112693899,
"recent_gifts":[
],
"class_id":3,
"bonus":{
"spy_defense":29700,
"plunder":172541048,
"attack":6720,
"defense":6720,
"spy_attack":29700
},
"superpower_expire_date":null,
"avatar_id":3,
"avatar_type":1,
"cost":38546404367
},
{
"username":"JesseJames1986",
"user_id":1018522130,
"recent_gifts":[
],
"class_id":3,
"bonus":{
"spy_defense":0,
"plunder":172541047,
"attack":98400,
"defense":86400,
"spy_attack":0
},
"superpower_expire_date":null,
"avatar_id":3,
"avatar_type":1,
"cost":38546404264
},
{
"username":"CobraVirus",
"user_id":1354087542,
"recent_gifts":[
],
"class_id":2,
"bonus":{
"spy_defense":2700,
"plunder":172541047,
"attack":47120,
"defense":44745,
"spy_attack":2700
},
"superpower_expire_date":null,
"avatar_id":2,
"avatar_type":1,
"cost":38546404120
},
{
"username":"TBONE762",
"user_id":1219855986,
"recent_gifts":[
],
"class_id":2,
"bonus":{
"spy_defense":151200,
"plunder":172540952,
"attack":2400,
"defense":1600,
"spy_attack":151200
},
"superpower_expire_date":null,
"avatar_id":2,
"avatar_type":1,
"cost":38546382898
},
{
"username":"Breaking_Force",
"user_id":884257658,
"recent_gifts":[
],
"class_id":2,
"bonus":{
"spy_defense":421500,
"plunder":172482744,
"attack":59740,
"defense":59740,
"spy_attack":421500
},
"superpower_expire_date":null,
"avatar_id":2,
"avatar_type":1,
"cost":38533379145
},
{
"username":"llllIllllIllllIllllIllllIlllIl",
"user_id":682935410,
"recent_gifts":[
],
"class_id":2,
"bonus":{
"spy_defense":408000,
"plunder":172482744,
"attack":87366,
"defense":87366,
"spy_attack":408000
},
"superpower_expire_date":null,
"avatar_id":2,
"avatar_type":1,
"cost":38533379141
},
{
"username":"yenhong11",
"user_id":1991515969,
"recent_gifts":[
],
"class_id":2,
"bonus":{
"spy_defense":45900,
"plunder":172482744,
"attack":302400,
"defense":201600,
"spy_attack":45900
},
"superpower_expire_date":null,
"avatar_id":2,
"avatar_type":1,
"cost":38533379134
},
{
"username":"-X3X-vv3vv-X3X-",
"user_id":1354192816,
"recent_gifts":[
],
"class_id":4,
"bonus":{
"spy_defense":7650,
"plunder":172482744,
"attack":28800,
"defense":36075,
"spy_attack":3600
},
"superpower_expire_date":null,
"avatar_id":4,
"avatar_type":2,
"cost":38533379130
},
{
"username":"PrimeMerlinian",
"user_id":1186326288,
"recent_gifts":[
],
"class_id":4,
"bonus":{
"spy_defense":302400,
"plunder":172482744,
"attack":0,
"defense":0,
"spy_attack":302400
},
"superpower_expire_date":null,
"avatar_id":4,
"avatar_type":1,
"cost":38533379130
},
{
"username":"samiloubra",
"user_id":78964704,
"recent_gifts":[
],
"class_id":2,
"bonus":{
"spy_defense":75900,
"plunder":172482744,
"attack":346720,
"defense":242080,
"spy_attack":75900
},
"superpower_expire_date":null,
"avatar_id":2,
"avatar_type":2,
"cost":38533379127
},
{
"username":"DARK_Pandora_ANGEL",
"user_id":1555414419,
"recent_gifts":[
],
"class_id":4,
"bonus":{
"spy_defense":218700,
"plunder":172482744,
"attack":21120,
"defense":16320,
"spy_attack":218700
},
"superpower_expire_date":null,
"avatar_id":4,
"avatar_type":1,
"cost":38533379127
}
]
}
我将如何去把这个放入在C#中的数组?然后找到用户名最奖金统计相结合?我还没有得到过去JSON一部分有配发的线程会有点无处不在。
How would I go about putting this into an array in C#? Then Finding the username with the most bonus stats combined? I haven't gotten past the json part as there is allot of threads will little everywhere.
推荐答案
首先,构建了一个User类:
First, build a User class:
public class User
{
public int AvatarId { get; set; }
public int AvatarType { get; set; }
public Bonus BonusValues { get; set; }
....
}
public class Bonus
{
public int Attack { get; set; }
public int Defense { get; set; }
....
}
然后反序列化JSON字符串到该对象。
Then deserialize the json string into this object.
List<User> users = JsonConvert.DeserializeObject<List<User>>(json);
对不起,我没有时间去有一些充分的测试code你。但是,你应该明白了吧。一旦你的C#对象,它会很容易为你计算出总奖金点等。请让我知道,如果你有任何困难。我会回来今晚计算器
Sorry I have no time to have some fully tested code for you. But you should get the idea. Once you have the C# object, it will be easy for you to calculate the total Bonus point and so on. Please let me know if you have any difficulties. I will come back to Stackoverflow tonight.
这篇关于C#的Json - 到 - 阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!