C #을 사용하여 JSON 파일의 값을 변경하려고하지만 값이 변경되지 않습니다. 아래는 JSON입니다. 변경하려고합니다.
{
"client": {
"name": "ClientName",
"pageTitle": "PageTitle",
"serverId": 234
},
"connection": {
"router": {
"webSocketURL": "wss://pbnasdadasdasd",
"signalRUrl": "https://pbncrasdasdasdasd",
"endPoint": "https://pbncasdasdadasd",
"type": "BabelFish",
"protocol": "WebClientGameplayProtocol.WebClientGameplayProtocolDefinition",
"transport": [
"webSockets"
]
}
}
}
이것이 메서드에서 내 C # 코드의 모습입니다.
string json = File.ReadAllText(Jsonfile);
dynamic jsonObj = Newtonsoft.Json.JsonConvert.DeserializeObject(json);
jsonObj["client"]["serverId"] = "7001";
jsonObj["client"]["connection"]["router"]["webSocketURL"] = "wss://xrouter.program.eu";
jsonObj["client"]["connection"]["router"]["signalRUrl"] = "https://xrouter.program.eu/h";
jsonObj["client"]["connection"]["router"]["endPoint"] = "https://xrouter.program.eu/";
코드를 실행할 때 'NULL 참조에서 런타임 바인딩을 수행 할 수 없음'오류가 발생하고 해당 영역에 이미 값이있는 이유를 알 수 없습니다. **** 더 이상이 오류가 발생하지 않습니다. jsonObj ****
아래 오류를 참조하십시오.
미리 감사드립니다.
이 오류는 때문이다 jsonObj["client"]["connection"]..
경우 ["client"]
에 대한 나던 존재하는 connection
속성. 또한 사용해보십시오JObject.Parse
string json = File.ReadAllText(Jsonfile);
var jsonObj = JObject.Parse(json);
jsonObj["client"]["serverId"] = "7001";
jsonObj["connection"]["router"]["webSocketURL"] = "wss://xrouter.program.eu";
jsonObj["connection"]["router"]["signalRUrl"] = "https://xrouter.program.eu/h";
jsonObj["connection"]["router"]["endPoint"] = "https://xrouter.program.eu/";
Console.WriteLine(jsonObj.ToString());
산출
{
"client": {
"name": "ClientName",
"pageTitle": "PageTitle",
"serverId": "7001"
},
"connection": {
"router": {
"webSocketURL": "wss://xrouter.program.eu",
"signalRUrl": "https://xrouter.program.eu/h",
"endPoint": "https://xrouter.program.eu/",
"type": "BabelFish",
"protocol": "WebClientGameplayProtocol.WebClientGameplayProtocolDefinition",
"transport": [
"webSockets"
]
}
}
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다