反序列化,编辑和保存JSON文件

时间:2019-03-11 22:03:27

标签: asp.net .net json vb.net json.net

我正在使用Json.NET,并且具有以下JSON文件。我想要做的是能够添加新的文件并从文件中删除现有的“ DicomModalities”并保存回结果。

  {
  "Name": "PACS",
  "StorageDirectory": "new password",
  "StorageCompression": false,
  "MaximumStorageSize": 0,
  "MaximumPatientCount": 0,
  "Plugins": [
    "C:/Orthanc/Plugins/"
  ],
  "PostgreSQL": {
    "EnableIndex": true,
    "EnableStorage": false,
    "Host": "127.0.0.1",
    "Port": 5432,
    "Database": "ort",
    "Username": "postgres",
    "Password": "77"
  },
  "HttpServerEnabled": true,
  "HttpPort": 8042,
  "HttpDescribeErrors": true,
  "HttpCompressionEnabled": true,
  "RegisteredUsers": {
    "ace": "bat67"
  },
  "DicomModalities" : {
    "Mod1" : {
        "AET": "INSTANCE-A",
        "Port": 123,
        "Host": "10.0.0.1",
        "AllowEcho": true,
        "AllowFind": false,
        "AllowMove": false,
        "AllowStore": false
    },

    "Mod2" : {
        "AET": "INSTANCE-B",
        "Port": 123,
        "Host": "10.0.0.1",
        "AllowEcho": true,
        "AllowFind": false,
        "AllowMove": false,
        "AllowStore": false
    }
},
  "DicomAlwaysAllowStore": false,
  "DicomCheckModalityHost": false,
  "DicomScuTimeout": 10,
  "Dictionary": {}
}

到目前为止,我已经能够创建一个新的“ DicomModalities”对象并对其进行序列化,但是可以弄清楚如何将其添加到文件中或删除现有的“ DicomModalities”对象,例如“ Mod1”,“ Mod2”

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim modality As Modality = New Modality()
        modality.AET = "AET"
        modality.Port = 111
        modality.Host = "22.66.77.88"
        modality.AllowEcho = False
        modality.AllowFind = True
        modality.AllowMove = False
        modality.AllowStore = True

        Dim output As String = JsonConvert.SerializeObject(modality)
        MsgBox(output)
    End Sub

    Public Class Modality
        Public Property AET As String
        Public Property Port As Integer
        Public Property Host As String
        Public Property AllowEcho As Boolean
        Public Property AllowFind As Boolean
        Public Property AllowMove As Boolean
        Public Property AllowStore As Boolean
    End Class

非常感谢您的帮助。

0 个答案:

没有答案