タイトルについて申し訳ありませんが、正直なところ、そこの問題を説明する方法がわかりませんでした。とにかく、ここに私の苦境があります。現在、情報ファイルを解析しています。その「作成者」および「依存関係」セクションも同様です。ただし、info ファイルの作成者には、別の方法で記述するオプションがあります。次のように記述できます。
"authors" : [ "author1", "author2" ],
また:
"authors": ["author1", "author 2"],
両方のスタイルを次のように変換する必要があります。
author1, author2
解析しようとしているファイルは次のようになります。
-snip "authors": [ "author1", "author2", "author3" -snip
私は、著者が書いた 2 番目の方法で解析することに成功しました。ただし、最初の方法で解析しようとすると、NullReference 例外が発生します。例外の詳細は次のとおりです。
System.NullReferenceException はユーザー コードによって処理されませんでした。HResult=-2147467261 Message=オブジェクト参照がオブジェクトのインスタンスに設定されていません。Source=RKs Tool Kit StackTrace: at RK_Tool_kit.ParseModInfo.getAuthors(String path) in C:\Users\Sam\Desktop\Programing\C# Projects\RK Mod Installer\RK Mod Installer\RK Mod Installer\ParseModInfo.cs:line 119 C:\Users\Sam\Desktop\Programing\C# Projects\RK Mod Installer\RK Mod Installer\RK Mod Installer\AddMods.cs:line 85 at System.Windows の RK_Tool_kit.AddMods.txtbxAddMods_DragDrop(Object sender, DragEventArgs e) .Forms.Control.OnDragDrop(DragEventArgs drgevent) を System.Windows.Forms.Control.System.Windows.Forms.IDropTarget.OnDragDrop(DragEventArgs drgEvent) で System.Windows.Forms.DropTarget.System.Windows.Forms.
内部例外:
私はここで途方に暮れています。よろしくお願いします。これが私のコードです:
public static string getAuthors(string path)
{
string line;
using (StreamReader sr = new StreamReader(path))
{
while (!sr.EndOfStream)
{
line = sr.ReadLine();
if (line.Contains("author"))
{
//This detects if it is the second way the authors can write it
if (line.Contains("[") && line.Contains("]"))
{
line = line.Replace("\"authors\": ", "").Replace("\"authors\" : ", "").Replace("\"authorList\": ", "").Replace("\"authorList\" : ", "").Replace("[", "").Replace("]", "").Replace("\"", "").TrimStart(toTrim);
int Place = line.LastIndexOf(",");
string comma = ",";
line = line.Remove(Place, comma.Length).Insert(Place, "");
return line;
}
//This means the the author wrote it the first way. And the string "line" just says '"authors": [' so we want to read the line again.
else
{
line = sr.ReadLine();
line = line.Replace("\"", "").TrimStart(toTrim);
for (int i = 0; i < 101; i++)
{
//This checks to see if there is only one author in the array. If there is a comma, we want to read another line because there is another author.
if (line.Contains(","))
{
//THIS RIGHT HERE throws the exception
line = line + sr.ReadLine().Replace("\"", "").TrimStart(toTrim);
}
else
{
break;
}
}
return line;
}
}
}
}
return "N/A";
}