Change values in JSON file (writing files)

后端 未结 4 2216
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-27 15:55

I have a settings.json file present in the Release folder of my application. What I want to do is change the value of it, not temporarily, permanently.. That means, deleting

4条回答
  •  离开以前
    2020-11-27 16:35

    I have been able to use the info above to get 2/3rds of my program working. I am updating three values.

    .json format snippet:

    { "Version": "1.0.0", "SignBatches": [ { "SourceRootDirectory": "c:\red", "DestinationRootDirectory": "d:\green", "SignRequestFiles": [ { "SourceLocation": "billboard-GS_PariahHeart-v1.lzp" } ],

    Code that works:

    jsonObj["SignBatches"][0]["SourceRootDirectory"] = Path.GetDirectoryName(args[0]);

    jsonObj["SignBatches"][0]["DestinationRootDirectory"] = Path.GetDirectoryName(args[1]);

    Code that fails:

    jsonObj["SignRequestFiles"][0]["SourceLocation"] = Path.GetFileName(args[0]);

    Note that this is trying to update a value of a nested object in the .json file. the previous two lines are updating a similar value, but they are at the top level.

    The error generated is:

    Unhandled exception. Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: Cannot perform runtime binding on a null reference

提交回复
热议问题