我有一個JSON字符串,我希望能夠在C#中修改。我希望能夠在滿足特定條件時更新結果中的值。從JSON更新基於C中條件的元素#
採取以下
{
"responseHeader":{
"status":0,
"QTime":0,
"params":{
"explainOther":"",
"fl":"*,score",
"indent":"on",
"start":"0",
"q":"*:*",
"hl.fl":"",
"qt":"",
"wt":"json",
"fq":"",
"version":"2.2",
"rows":"2"}
},
"response":{"numFound":2,"start":0,"maxScore":1.0,"docs":
[{
"id":"438500feb7714fbd9504a028883d2860",
"name":"John",
"email":"[email protected]"
"dateTimeCreated":"2012-02-07T15:00:42Z",
"dateTimeUploaded":"2012-08-09T15:30:57Z",
"score":1.0
},
{
"id":"2f7661ae3c7a42dd9f2eb1946262cd24",
"name":"David",
"email":"[email protected]"
"dateTimeCreated":"2012-02-07T15:02:37Z",
"dateTimeUploaded":"2012-08-09T15:45:06Z",
"score":1.0
}]
}}
我希望能夠以更新的姓名和電子郵件元素值,當我找到一個包含特定ID的結果。
例如,我想要更新名稱和電子郵件元素,其中該文檔ID等於「438500feb7714fbd9504a028883d2860」,並將名稱值更新爲Richard並將電子郵件值更新爲[email protected]。結果如下所示。
{
"responseHeader":{
"status":0,
"QTime":0,
"params":{
"explainOther":"",
"fl":"*,score",
"indent":"on",
"start":"0",
"q":"*:*",
"hl.fl":"",
"qt":"",
"wt":"json",
"fq":"",
"version":"2.2",
"rows":"2"}
},
"response":{"numFound":2,"start":0,"maxScore":1.0,"docs":
[{
"id":"438500feb7714fbd9504a028883d2860",
"name":"Richard",
"email":"[email protected]"
"dateTimeCreated":"2012-02-07T15:00:42Z",
"dateTimeUploaded":"2012-08-09T15:30:57Z",
"score":1.0
},
{
"id":"2f7661ae3c7a42dd9f2eb1946262cd24",
"name":"David",
"email":"[email protected]"
"dateTimeCreated":"2012-02-07T15:02:37Z",
"dateTimeUploaded":"2012-08-09T15:45:06Z",
"score":1.0
}]
}}
性能是一個考慮因素,因爲我需要處理許多JSON字符串,所以請牢記這一點。
在此先感謝 安德魯
解碼JSON,更改值,序列化爲JSON。 –
@Asad回答這個問題! –