我正在搞亂Steam Web API。我試圖做一個功能,它會找到一段文字,然後提取另一段文字,這將改變,這取決於我用功能查找用戶。C#在字符串中查找文本,然後提取一個變量
我試過使用IndexOf,但由於我想提取的文本可能會有所不同,它是相當困難的。
Json響應我想從這樣的字符串中提取字符串,但是每個查找的用戶都不一樣。
{
"response": {
"game_count": 54,
"games": [
{
"appid": 240,
"playtime_forever": 51842
},
{
"appid": 260,
"playtime_forever": 43
},
{
"appid": 300,
"playtime_forever": 191
},
{
"appid": 320,
"playtime_forever": 130
},
{
"appid": 340,
"playtime_forever": 4
},
{
"appid": 520
},
{
"appid": 4000,
"playtime_2weeks": 798,
"playtime_forever": 61803
},
{
"appid": 440,
"playtime_forever": 19466
},
{
"appid": 105600,
"playtime_forever": 2084
},
{
"appid": 72850,
"playtime_forever": 2010
},
{
"appid": 380,
"playtime_forever": 91
},
{
"appid": 400,
"playtime_forever": 76
},
{
"appid": 420
},
{
"appid": 220,
"playtime_forever": 827
},
{
"appid": 550,
"playtime_forever": 906
},
{
"appid": 33910,
"playtime_forever": 77
},
{
"appid": 33930,
"playtime_2weeks": 1714,
"playtime_forever": 31904
},
{
"appid": 219540,
"playtime_forever": 0
},
{
"appid": 570
},
{
"appid": 205790
},
{
"appid": 22380,
"playtime_forever": 1119
},
{
"appid": 105400,
"playtime_forever": 134
},
{
"appid": 204030
},
{
"appid": 12120
},
{
"appid": 12250
},
{
"appid": 24010
},
{
"appid": 8190,
"playtime_forever": 723
},
{
"appid": 620,
"playtime_forever": 101
},
{
"appid": 644
},
{
"appid": 730,
"playtime_forever": 431
},
{
"appid": 10,
"playtime_forever": 396
},
{
"appid": 80
},
{
"appid": 100
},
{
"appid": 42680,
"playtime_forever": 65
},
{
"appid": 42690,
"playtime_forever": 1435
},
{
"appid": 22200
},
{
"appid": 113200,
"playtime_forever": 270
},
{
"appid": 20540
},
{
"appid": 55110
},
{
"appid": 43110
},
{
"appid": 9340
},
{
"appid": 50620
},
{
"appid": 4560
},
{
"appid": 55230,
"playtime_forever": 1354
},
{
"appid": 4540
},
{
"appid": 4570
},
{
"appid": 22370,
"playtime_forever": 305
},
{
"appid": 70,
"playtime_forever": 479
},
{
"appid": 70300,
"playtime_forever": 138
},
{
"appid": 220240,
"playtime_2weeks": 72,
"playtime_forever": 453
},
{
"appid": 107410,
"playtime_2weeks": 80,
"playtime_forever": 403
},
{
"appid": 40800,
"playtime_2weeks": 124,
"playtime_forever": 124
},
{
"appid": 12210,
"playtime_2weeks": 663,
"playtime_forever": 663
},
{
"appid": 12220,
"playtime_2weeks": 658,
"playtime_forever": 658
}
]
}
}
我想要做的,是搜索,即「\」 APPID \「440」,然後能夠得到這來後playtime_forever INT。我無能爲力。如果字符串具有設定的長度,我只能從Split函數中獲得幫助,因爲那樣我可以返回我想要的數組索引。
我非常抱歉,如果這不明確,我盡我所能解釋我想要達到的目標。
由於提前,
伊薩克
你有沒有考慮過使用[jObject](http://james.newtonking.com/projects/json/help/html/T_Newtonsoft_Json_Linq_JObject.htm)? – DGibbs 2013-04-08 11:58:41
嚴重的是,爲什麼你在嘗試編寫JSON解析器時已經有很多這樣的解析器了? – spender 2013-04-08 11:59:09
您可以使用http://json.codeplex.com/並使用JSON序列化程序。或者你可以在.NET中使用正則表達式來提取它。 – Robert 2013-04-08 11:58:52