【发布时间】:2017-04-24 00:21:44
【问题描述】:
我正在尝试在 JObject 对象的数组中找出字符串的索引。例如,你可以给 frc610,它会返回 0。
// Get rankings JSON file from thebluealliance.com
string TBArankings = @"https://www.thebluealliance.com/api/v2/district/ont/2017/rankings?X-TBA-App-Id=frc2706:ONT-ranking-system:v01";
var rankings = new WebClient().DownloadString(TBArankings);
string usableTeamNumber = "frc" + teamNumberString;
string team_key = "";
int rank = 0;
dynamic arr = JsonConvert.DeserializeObject(rankings);
foreach (dynamic obj in arr)
{
team_key = obj.team_key;
rank = obj.rank;
}
int index = Array.IndexOf(arr, (string)usableTeamNumber); // <-- This is where the exception is thrown.
Console.WriteLine(index);
// Wait 20 seconds
System.Threading.Thread.Sleep(20000);
Here's the json file I'm using。
我尝试了多种不同的解决方案,但都没有奏效。
【问题讨论】: