c# json转义单双引号的问题。


   
  public string deviceInfo = "\"error\":\"getUserUniqueInfoError\"";
  
String str = "{\"sid\":\"" + globalConfig.platid + "\",\"did\":\"" + globalConfig.did + "\",\"version\":\"" + globalConfig.versionCode +
"\",\"param\":{\"uid\":\""+ id + "\"," + deviceInfo+ ",\"bid\":\""+ bid +"\",\"mobid\":\"" + mobid + "\",\"nick\":\""+globalConfig.nickName+
"\",\"token\":\""+ globalConfig.accessToken +"\"}}";


为什么在代码执行过程中,这个地方deviceInfo 会变成'error':'getUserUniqueInfoError' 有没有办法让他是
"error":"getUserUniqueInfoError" ?或者说我应该怎样定义deviceInfo的格式或者str的格式使得代码执行过程中这里是"error":"getUserUniqueInfoError",而不出现'error':'getUserUniqueInfoError' ?

json c#

新世界D法老 10 years, 6 months ago

转义符就可以了(“对应的是\")

harqi answered 10 years, 6 months ago

Your Answer