[英]how to prevent JsonConvert.SerializeObject from adding quotes around strings
I have a section on my server that looks like this: 我的服务器上有一个部分如下所示:
private static dynamic Data;
string ArraySize = "[900,900,2]";
Data = new { c2array = true, size = ArraySize };
System.IO.File.WriteAllText("json.txt", JsonConvert.SerializeObject(Data));
which spits this out: 这吐出来:
{"c2array":true,"size":"[900,900,2]"} {“ c2array”:true,“ size”:“ [900,900,2]”}
yet in JavaScript I can get it to this with json.stringify: 但是在JavaScript中,我可以通过json.stringify来实现:
{"c2array":true,"size":[900,900,2]} <--- no quotes {“ c2array”:true,“ size”:[900,900,2]} <---无引号
how can i get the c# JSON serialize to not wrap quotes around the string. 我如何才能将c#JSON序列化为不将引号引起来的字符串。
I'm using a string value because if I try the following 我使用的是字符串值,因为如果尝试以下操作
Data = new { c2array = true, size = [900,900,2] };
it won't compile 它不会编译
the client script I'm sending this to is a game programming library in JavaScript and it expects the size without quotes. 我要发送给它的客户端脚本是JavaScript中的游戏编程库,它期望的大小不带引号。
Don't make ArraySize
a string. 不要将ArraySize
为字符串。
var ArraySize = new int[] {900,900,2};
Data = new { c2array = true, size = ArraySize };
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.