-1
我建立在視覺工作室2015年C#WPF應用程序,需要能夠從應用C#我如何使用文本框編輯JSON的具體線路
編輯配置文件在我有一個應用程序帶有一些文本框的TabItem,這些文本框由來自S3 Bucket的配置文件請求填充。
文本框將填入的選擇更改事件的基礎從ComboBox
這裏的問題是能夠編輯特定的路線,每次我試圖我覆蓋了整個配置只新的數據,而不是編輯當前數據。
這是我正在使用的JSON結構。
[
{
"ClientId": 23,
"EmailVersionId": "u74hdta58jmf",
"ClientName": "ClientName",
"emailTemplateConfigs": [
{
"emailTypeName": "EmailName",
"emailTypeId": 15,
"subject": "subject",
"fromAddress": "from address",
"headerFooterReplacements": [
{
"placeholder": "##HEADER_PHONENUMBER##",
"value": "0000 000 000"
},
{
"placeholder": "##HTML_TITLE##",
"value": "Title"
},
{
"placeholder": "##EMAIL_HEADING##",
"value": "Heading"
}
]
},
{
"emailTypeName": "EmailName",
"emailTypeId": 29,
"subject": "subject",
"fromAddress": "from address",
"headerFooterReplacements": [
{
"placeholder": "##HEADER_PHONENUMBER##",
"value": "0000 000 000"
},
{
"placeholder": "##HTML_TITLE##",
"value": "Title"
},
{
"placeholder": "##EMAIL_HEADING##",
"value": "Heading"
}
]
}
]
},
{
"ClientId": 33,
"EmailVersionId": "jcna53sj231h",
"ClientName": "ClientName",
"emailTemplateConfigs": [
{
"emailTypeName": "EmailName",
"emailTypeId": 12,
"subject": "subject",
"fromAddress": "from address",
"headerFooterReplacements": [
{
"placeholder": "##HEADER_PHONENUMBER##",
"value": "0000 000 000"
},
{
"placeholder": "##HTML_TITLE##",
"value": "Title"
},
{
"placeholder": "##EMAIL_HEADING##",
"value": "Heading"
}
]
},
{
"emailTypeName": "EmailName",
"emailTypeId": 49,
"subject": "subject",
"fromAddress": "from address",
"headerFooterReplacements": [
{
"placeholder": "##HEADER_PHONENUMBER##",
"value": "0000 000 000"
},
{
"placeholder": "##HTML_TITLE##",
"value": "Title"
},
{
"placeholder": "##EMAIL_HEADING##",
"value": "Heading"
}
]
}
]
}
]
我試圖用文本框更新的部分是
"emailTypeName": "EmailName",
"emailTypeId": 15,
"subject": "subject",
"fromAddress": "from address",
但做編輯時,還需要使用客戶端來保存信息,以正確的客戶端和正確的模板ID和電子郵件類型ID作爲鍵。
GetObjectRequest requestconfig = new GetObjectRequest();
requestconfig.BucketName = "bucket";
requestconfig.Key = "key";
GetObjectResponse response = s3Client.GetObject(requestconfig);
using (StreamReader r = new StreamReader(response.ResponseStream))
{
string json = r.ReadToEnd();
dynamic jsonObj = JsonConvert.DeserializeObject(json);
if ((int)emailTempConfig.emailTypeId == templateID)
{
jsonObj["EmailTemplateConfig"][0]["EmailsTypeName"] = EmailNameText.Text;
output = JsonConvert.SerializeObject(jsonObj, Formatting.Indented);
}
}
PutObjectRequest requestConfig = new PutObjectRequest();
requestConfig.BucketName = "bucket";
requestConfig.Key = "key";
requestConfig.ContentType = "application/json";
requestConfig.ContentBody = output;
s3Client.PutObject(requestConfig);
這就是我所在的代碼。