所以我正在做一个项目。我想创建一个将.json字幕转换为.srt的软件。大多数网站都使用.json。所以我几乎是在谷歌的帮助下做的(我是新手到c#),现在我唯一遇到的麻烦就是从.json文件中读取行的循环。有人可以帮忙吗 这是代码
static void Main(string[] args)
{
string src = Console.ReadLine();
Console.Clear();
int i = 1;
foreach (var myString in File.ReadAllLines(src))
{
string startTime = getBetween(myString, "\"startTime\":", ",\"guid\":");
string endTime = getBetween(myString, "\"endTime\":", ",\"id\":");
string text = getBetween(myString, "\"Text\":\"", "\",");
startTime = start(startTime);
endTime = end(endTime);
Console.WriteLine(i);
Console.WriteLine("{0} --> {1}", startTime, endTime);
Console.WriteLine(text);
Console.WriteLine();
i++;
}
}
它只是读取第一行并停止。
这里有一些.json文件:
[{
"hitType": "tag",
"subTrack": null,
"tags": [],
"track": "Closed Captioning",
"startTime": 0.062,
"guid": "549008c4-c9ac-4f1d-8287-228e8801b81e",
"segmentTypeId": "4cb53a3908b1cb506e00002d",
"endTime": 2.025,
"id": "58863f95297bb618079dd88c",
"metadata": {
"Text": "Barry: My name is Barry Allen,",
"ID": "",
"Language": "en"
}
}]