.net - C# StringBuilder with Quotes (forJSON) -
i have build json string (to posted web service), , used c# stringbuilder class this. problem is, when insert quotes, stringbuilder class escapes them.
i building json string such:
stringbuilder datajson= new stringbuilder(); datajson.append("{"); datajson.append(" " + convert.tochar(34) + "data" + convert.tochar(34) + ": {"); datajson.append(" " + convert.tochar(34) + "urls" + convert.tochar(34) + ": ["); datajson.append(" {" + convert.tochar(34) + "url" + convert.tochar(34) + ": " + convert.tochar(34) + domain + "/" + path[0] + convert.tochar(34) + "}"); datajson.append(" ,{" + convert.tochar(34) + "url" + convert.tochar(34) + ": " + convert.tochar(34) + domain + "/" + path[1] + convert.tochar(34) + "}"); datajson.append(" ]"); datajson.append(" }"); datajson.append("}");
however, command: datajson.tostring();
results in string:
{ \"data\": { \"urls\": [ {\"url\": \"domain/test1.html\"} , {\"url\": \"domain/test2.html\"} ] }}
notice escaped quotes? screwing me up, because server can't handle slashes.
my desired (which posts fine server when use php) should be:
{ "data": { "urls": [ {"url": "domain/test1.html"} , {"url": "domain/test2.html"} ] }}
is there way string in c# include quotes result in desired string?
many thanks! brett
the quickwatch/watch window add \
in. if view in text visualizer, not see them:
quickwatch:
"{ \"data\": { \"urls\": [ {\"url\": \"domain/path1\"} ,{\"url\": \"domain/path2\"} ] }}"
visualizer (the actual output):
{ "data": { "urls": [ {"url": "domain/path1"} ,{"url": "domain/path2"} ] }}
the \
indicates quotes have been escaped , included in final string you're expecting them be. i.e. there's nothing wrong output.
nb. used "\""
instead of convert.tochar(34)
when tested this.
Comments
Post a Comment