[英]C# JSON.NET - Convert Array to JSON string thats including url
我想将对象转换为JSON字符串。 该对象包含两个属性: 名称和URL
WebsiteInfo _wbInfo = new WebsiteInfo();
_wbInfo.WebsiteName = "MyWebsite";
_wbInfo.URL = "http://example.com/";
string _jsonString = JsonConvert.SerializeObject(_wbInfo);
结果如下:
{"WebsiteName":"MyWebsite","URL":"http://example.com/"}
到目前为止一切顺利,但是如果我将此json字符串发送到JSON服务,则会收到错误消息“ 404 Not Found”。
这是我的完整网址:
http://localhost:63124/Test/{"WebsiteName":"MyWebsite","URL":"http://example.com/"}
如果我执行此命令(不带斜杠“ /”),它将起作用:
http://localhost:63124/Test/{"WebsiteName":"MyWebsite","URL":"http:example.com"}
同样,使用转义的斜杠将不起作用:
http://localhost:63124/Test/{"WebsiteName":"MyWebsite","URL":"http:%2F%2F/example.com%2F"}
这是我的JSON服务:
[OperationContract]
[WebInvoke(Method = "GET", UriTemplate = "/Test/{WebsiteInfo}", ResponseFormat = WebMessageFormat.Json)]
string Test(string WebsiteInfo);
简而言之,您无法以此处尝试的方式发送JSON。
您的JSON对象应改为在请求正文中发送。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.