Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#删除JSON文件中的文本_C#_Json - Fatal编程技术网

C#删除JSON文件中的文本

C#删除JSON文件中的文本,c#,json,C#,Json,我正在尝试从c#创建一个json文件。如果该数组为空,则需要删除该数组“JudgementLinkedAccount”:[]。我试过: public static void ReplaceText() { string text = File.ReadAllText(FileToExport.exportFile); string textToReplace = "\"" + "judgmentLinkedAccount" + "\"" + ":

我正在尝试从c#创建一个json文件。如果该数组为空,则需要删除该数组“JudgementLinkedAccount”:[]。我试过:

    public static void ReplaceText() 
    {
        string text = File.ReadAllText(FileToExport.exportFile);
        string textToReplace = "\"" + "judgmentLinkedAccount" + "\"" + ": []";
        text = text.Replace(textToReplace, "");
        File.WriteAllText(FileToExport.exportFile, text);
    }
但它不会删除文本。
感谢您的帮助。

使用textToReplace=“\”判断LinkedAccount\”:[]”更改textToReplace的内容

1)能否共享一个显示输入JSON的文件?2) 您正在创建JSON吗?如果是这样,为什么不直接跳过序列化
判断LinkedAccount
成员?例如,如果您正在使用生成JSON,请参阅。