如何在没有属性标识符的情况下反序列化json?

时间:2015-07-09 20:34:32

标签: c# json json-deserialization

假设一串接近JSON的序列化数据,但它不包含属性标识符。而不是

{
    "data": "Click Here",
    "size": 36,
    "style": "bold",
    "name": "text1",
    "hOffset": 250,
    "vOffset": 100,
    "alignment": "center",
    "onMouseUp": "sun1.opacity = (sun1.opacity / 100) * 90;"
}

我只有

{"Click Here", 36, "bold", "text1", 250, 100, "center", "sun1.opacity = (sun1.opacity / 100) * 90;"}

在这种情况下,财产名称并不重要。例如,它们可以稍后分配为property1, property2 ...

我无法自动生成该类,因为这不是有效的JSON。 有没有办法识别这个类? ...然后将JSON反序列化为该类的对象?我更喜欢基于c#的建议。

如果有帮助,我会附上我正在处理的作品。

[[[4477929,"McGuire \/ Dowdy","Pazo \/ Gabi",32,"2015-07-07T06:50:00.0000000",[[10439425,39]],"0","0",1,[0,0,"2015-07-07T06:49:47.2870000",0],0,"\/sports\/beach-volleyball\/gstaad-grand-slam-women",,,10447,2,3,0,171.182,0,0,"\/sports\/beach-volleyball\/gstaad-grand-slam-women\/20150707\/mcguire-dowdy-vs-pazo-gabi\/",,,"","",[[168,"2"]],0,-1,-1,0,,0],[4477939,"Bonnerova \/ Hermannova","Turnerova \/ Tomasekova",32,"2015-07-07T06:55:00.0000000",[[10439444,39]],"0","0",1,[0,0,"2015-07-07T06:54:12.7370000",0],0,"\/sports\/beach-volleyball\/gstaad-grand-slam-women",,,10447,1,0,0,0,0,0,"\/sports\/beach-volleyball\/gstaad-grand-slam-women\/20150707\/bonnerova-hermannova-vs-turnerova-tomasekova\/",,,"","",[[168,"2"]],0,-1,-1,0,,0],[4477959,"Rosko \/ Tadic","Take \/ Mizoe",32,"2015-07-07T07:00:00.0000000",[[10439482,39]],"0","0",1,[0,0,"2015-07-07T07:02:07.3000000",0],0,"\/sports\/beach-volleyball\/gstaad-grand-slam-women",,,10447,1,0,0,0,0,0,"\/sports\/beach-volleyball\/gstaad-grand-slam-women\/20150707\/rosko-tadic-vs-take-mizoe\/",,,"","",[[168,"2"]],0,-1,-1,0,,0],[4477850,"CSB Blazers","EAC Generals",2,"2015-07-07T06:00:00.0000000",[[10439229,39]],"42","31",1,[-13,335,"2015-07-07T07:12:35.1870000",0],20,"\/sports\/basketball\/philippines-ncaa",,,23623,22,7,0,277.050728066826,0,0,"\/sports\/basketball\/philippines-ncaa\/20150707\/csb-blazers-vs-eac-generals\/",,,"","",[[102,"18"],[103,"7"],[104,"18"],[105,"20"],[106,"36"],[107,"27"],[110,"0"],[111,"0"],[168,"2"],[170,"0"],[171,"3"],[109,"4"],[115,"31"],[108,"6"],[114,"42"]],1,-1,-1,0,,0],[4477871,"Valeriya Strakhova","Daniela Farfan",6,"2015-07-07T06:00:00.0000000",[[10439287,39]],"23402","36151",1,[0,1,"2015-07-07T06:06:19.6200000",0],0,"\/sports\/tennis\/itf-tournaments",,,12403,1,4,0,208.003,0,0,"\/sports\/tennis\/itf-tournaments\/20150707\/valeriya-strakhova-vs-daniela-farfan\/",,,"","",[[168,"2"],[172,"0"]],0,-1,-1,0,,0],[4477895,"Laurynas Grigelis","Nicolae Frunza",6,"2015-07-07T06:35:00.0000000",[[10439370,39]],"4001","2002",1,[0,1,"2015-07-07T06:36:14.3870000",0],6,"\/sports\/tennis\/itf-tournaments",,,12403,4,1,0,5.94447577285767,0,0,"\/sports\/tennis\/itf-tournaments\/20150707\/laurynas-grigelis-vs-nicolae-frunza\/",,,"","",[[168,"2"],[172,"0"]],0,-1,-1,0,,0],[4477899,"Valeria Prosperi","Polina Novikova",6,"2015-07-07T06:35:00.0000000",[[10439375,39]],"5302","3001",1,[0,1,"2015-07-07T06:37:04.6830000",0],0,"\/sports\/tennis\/itf-tournaments",,,12403,1,1,0,3.8042,0,0,"\/sports\/tennis\/itf-tournaments\/20150707\/valeria-prosperi-vs-polina-novikova\/",,,"","",[[168,"2"]],0,-1,-1,0,,0],[4477901,"Amina Anshba","Tamari Sumbadze",6,"2015-07-07T06:35:00.0000000",[[10439378,39]],"36152","1001",1,[0,1,"2015-07-07T06:37:35.4700000",0],0,"\/sports\/tennis\/itf-tournaments",,,12403,1,0,0,0,0,0,"\/sports\/tennis\/itf-tournaments\/20150707\/amina-anshba-vs-tamari-sumbadze\/",,,"","",[[168,"2"]],0,-1,-1,0,,0],[4477903,"Anastasia Chikalkina","Aminat Kushkhova",6,"2015-07-07T06:35:00.0000000",[[10439381,39]],"3151","5002",1,[0,1,"2015-07-07T06:37:54.4900000",0],0,"\/sports\/tennis\/itf-tournaments",,,12403,1,0,0,0,0,0,"\/sports\/tennis\/itf-tournaments\/20150707\/anastasia-chikalkina-vs-aminat-kushkhova\/",,,"","",[[168,"2"]],0,-1,-1,0,,0],[4477905,"Matias Zukas","Razvan Bobleaga",6,"2015-07-07T06:07:00.0000000",[[10439385,39]],"5001","2002",1,[0,0,"2015-07-07T06:39:02.4470000",0],6,"\/sports\/tennis\/itf-tournaments",,,12403,4,1,0,3.8042,0,0,"\/sports\/tennis\/itf-tournaments\/20150707\/matias-zukas-vs-razvan-bobleaga\/",,,"","",[[168,"2"],[172,"0"]],0,-1,-1,0,,0],[4477961,"Momkoonthod \/ Plipuech","Han \/ Kato",6,"2015-07-07T07:00:00.0000000",[[10439485,39]],"152","2001",1,[0,1,"2015-07-07T07:05:55.4500000",0],0,"\/sports\/tennis\/itf-tournaments",,,12403,1,0,0,0,0,0,"\/sports\/tennis\/itf-tournaments\/20150707\/momkoonthod-plipuech-vs-han-kato\/",,,"","",[[168,"2"],[172,"1"]],0,-1,-1,0,,0],[4477963,"Lennart Zynga","Florian Lakat",6,"2015-07-07T07:00:00.0000000",[[10439488,39]],"301","2",1,[0,1,"2015-07-07T07:06:32.1800000",0],6,"\/sports\/tennis\/itf-tournaments",,,12403,4,0,0,0,0,0,"\/sports\/tennis\/itf-tournaments\/20150707\/lennart-zynga-vs-florian-lakat\/",,,"","",[[168,"2"],[172,"2"]],0,-1,-1,0,,0],[4477965,"Daniiar Duldaev","Mirko Cutuli",6,"2015-07-07T07:00:00.0000000",[[10439495,39]],"401","1152",1,[0,0,"2015-07-07T07:07:06.6300000",0],0,"\/sports\/tennis\/itf-tournaments",,,12403,1,0,0,0,0,0,"\/sports\/tennis\/itf-tournaments\/20150707\/daniiar-duldaev-vs-mirko-cutuli\/",,,"","",[[168,"2"],[172,"4"]],0,-1,-1,0,,0],[4477967,"Barkin Yalcinkale","Ilya Ivashka",6,"2015-07-07T07:00:00.0000000",[[10439498,39]],"2","1001",1,[0,1,"2015-07-07T07:07:34.3700000",0],6,"\/sports\/tennis\/itf-tournaments",,,12403,4,0,0,0,0,0,"\/sports\/tennis\/itf-tournaments\/20150707\/barkin-yalcinkale-vs-ilya-ivashka\/",,,"","",[[168,"2"],[172,"0"]],0,-1,-1,0,,0],[4476418,"Ching-Wen Hsu [TPE]","Ling Zhang [HKG]",6,"2015-07-07T05:05:00.0000000",[[10437440,39]],"5002","7001",1,[0,1,"2015-07-06T19:39:52.6800000",0],0,"\/sports\/tennis\/itf-women-bangkok",,,21116,1,2,0,10.715806559515,0,0,"\/sports\/tennis\/itf-women-bangkok\/20150707\/ching-wen-hsu-vs-ling-zhang-\/",,,"","",[[172,"0"],[168,"2"]],0,-1,-1,0,,0],[4476424,"Nagi Hanatani [JPN]","Nudnida Luangnam [THA]",6,"2015-07-07T05:05:00.0000000",[[10438853,39]],"151","152",1,[0,0,"2015-07-07T03:14:17.2400000",0],0,"\/sports\/tennis\/itf-women-bangkok",,,21116,1,1,0,3.10875,0,0,"\/sports\/tennis\/itf-women-bangkok\/20150707\/nagi-hanatani-vs-nudnida-luangnam-\/",,,"","",[[168,"2"],[172,"2"]],0,-1,-1,0,,0],[4477947,"China Uni [W]","Czech Rep Uni [W]",10,"2015-07-07T07:00:00.0000000",[[10439454,39]],"5","5",1,[1,61,"2015-07-07T07:01:44.0130000",0],7,"\/sports\/handball\/universiade-women",,,23738,12,1,0,3,0,0,"\/sports\/handball\/universiade-women\/20150707\/china-uni-vs-czech-rep-uni-\/",,,"","",[[168,"2"]],0,-1,-1,0,,0],[4477951,"Slovakia Uni [W]","Russia Uni [W]",10,"2015-07-07T07:00:00.0000000",[[10439462,39]],"2","5",1,[1,61,"2015-07-07T07:00:56.0130000",0],7,"\/sports\/handball\/universiade-women",,,23738,11,0,0,0,0,0,"\/sports\/handball\/universiade-women\/20150707\/slovakia-uni-vs-russia-uni-\/",,,"","",[[168,"2"]],0,-1,-1,0,,0],[4477955,"Uruguay Uni [W]","Brazil Uni [W]",10,"2015-07-07T07:00:00.0000000",[[10439470,39]],"2","5",1,[1,121,"2015-07-07T07:05:09.8530000",0],7,"\/sports\/handball\/universiade-women",,,23738,10,1,0,224,0,0,"\/sports\/handball\/universiade-women\/20150707\/uruguay-uni-vs-brazil-uni-\/",,,"","",[[168,"2"]],0,-1,-1,0,,0],[4477863,"Switzerland Uni","Canada Uni",19,"2015-07-07T06:00:00.0000000",[[10439255,39]],"1","0",1,[0,0,"2015-07-07T06:03:14.3600000",0],7,"\/sports\/volleyball\/universiade-men",,,10409,7,3,0,225.6874,0,0,"\/sports\/volleyball\/universiade-men\/20150707\/switzerland-uni-vs-canada-uni\/",,,"","",[[130,"25"],[131,"16"],[140,"1"],[141,"0"],[168,"2"],[132,"23"],[164,"1"],[133,"22"]],0,-1,-1,0,,0],[4475048,"Gabor Gerold","Ivan Juzbasic",26,"2015-07-07T06:30:00.0000000",[[10439446,39]],"0","0",1,[0,0,"2015-07-07T06:54:41.4230000",0],0,"\/sports\/table-tennis\/challenger-series",,,15363,1,2,0,8.5008,0,0,"\/sports\/table-tennis\/challenger-series\/20150707\/gabor-gerold-vs-ivan-juzbasic\/",,,"","",[[168,"2"]],0,-1,-1,0,,0],[4467339,"Sri Lanka [3rd Test]","Pakistan [3rd Test]",59,"2015-07-07T04:30:00.0000000",[[10413111,39]],"278 & 313","215 & 321\/3",1,[0,0,"2015-07-03T03:12:55.2830000",0],0,"\/sports\/cricket\/test-matches",,,19162,1,15,0,180.3224951318,0,0,"\/sports\/cricket\/test-matches\/20150707\/sri-lanka-vs-pakistan-\/",,,"","",[[165,"278 & 313"],[166,"215 & 321\/3"]],0,-1,-1,0,,0],[4477920,"Bangladesh","South Africa",59,"2015-07-07T06:45:00.0000000",[[10439403,39]],"0","29\/0",1,[0,0,"2015-07-07T06:43:45.6370000",0],0,"\/sports\/cricket\/twenty20-international",,,21809,1,4,0,1447.524,0,0,"\/sports\/cricket\/twenty20-international\/20150707\/bangladesh-vs-south-africa\/",,,"","",[[168,"2"],[165,"0"],[167,"1"],[166,"29\/0"]],0,-1,-1,0,,0]],[[32,"Beach Volleyball",32,"beach-volleyball",["Winner","Spread","Over\/Under"],0,0,"\/sports\/beach-volleyball\/",[]],[2,"Basketball",2,"basketball",["Moneyline","Spread","Over\/Under"],0,0,"\/sports\/basketball\/",[]],[6,"Tennis",6,"tennis",["Winner","Handicap","Over\/Under"],0,0,"\/sports\/tennis\/",[]],[10,"Handball",10,"handball",["1x2","Spread","Over\/Under"],0,0,"\/sports\/handball\/",[]],[19,"Volleyball",19,"volleyball",["Winner","Sets Handicap","Over\/Under"],0,0,"\/sports\/volleyball\/",[]],[26,"Table Tennis",26,"table-tennis",["MoneyLine","Spread","Over\/Under"],0,0,"\/sports\/table-tennis\/",[]],[59,"Cricket",59,"cricket",["MoneyLine","Spread","Over\/Under"],0,0,"\/sports\/cricket\/",[]]],[[10447,"Gstaad Grand Slam Women",0,700,0,,0,,32,"International",245,"ZZ","\/sports\/beach-volleyball\/gstaad-grand-slam-women\/"],[23623,"Philippines NCAA",0,190,0,,0,,2,"Philippines",173,"PH","\/sports\/basketball\/philippines-ncaa\/"],[12403,"ITF Tournaments",0,1192,0,,0,,6,"International",245,"ZZ","\/sports\/tennis\/itf-tournaments\/"],[21116,"ITF Women Bangkok",0,1233,0,,0,,6,"Thailand",211,"TH","\/sports\/tennis\/itf-women-bangkok\/"],[23738,"Universiade Women",0,1064,0,,0,,10,"International",245,"ZZ","\/sports\/handball\/universiade-women\/"],[10409,"Universiade Men",0,924,0,,0,,19,"International",245,"ZZ","\/sports\/volleyball\/universiade-men\/"],[15363,"Challenger Series",0,640,0,,0,,26,"Europe",256,"EU","\/sports\/table-tennis\/challenger-series\/"],[19162,"Test Matches",0,509,0,,0,,59,"International",245,"ZZ","\/sports\/cricket\/test-matches\/"],[21809,"Twenty20 International",0,661,0,,0,,59,"International",245,"ZZ","\/sports\/cricket\/twenty20-international\/"]],[]]

1 个答案:

答案 0 :(得分:0)

您可以尝试使用单个属性(即数组)将其转换为JSON对象。快速浏览它并没有显示任何奇怪的东西,所以你可以尝试的最简单的事情就是:

string data = "[...]"; // your sample data above
string jsonData = "{'data':" + data + "}";

然后尝试在jsonData上运行JSON解析器。这仍然没有解决这些是某种记录的问题,但没有什么可以保证它们都具有相同的结构,也没有帮助你了解数据的含义,但至少应该给你一个简单的迭代方法数据。

请注意,您可能需要进行额外的转换,因为我注意到有很多,,序列,这​​取决于JSON解析器可能会抛出错误或被视为空元素。 (而且我不记得标准是否允许它)为了安全起见,我建议你快速查找并替换,,之类的,{},(空JSON对象) ,,"null",(一个永远不会在常规数据中显示的知名字符串),或者其他您可以轻松识别的字符串。