2016-11-30 86 views
2

我想将对象转换为JSON字符串。 对象包含两个属性:名称URLC#JSON.NET - 将数组转换为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); 
+1

为什么你不使用POST方法,而是GET?并且发送数据模型不是像uri的一部分,而是像内容那样? –

回答

0

简而言之,您无法以您在此尝试的方式发送JSON。

您的JSON对象应该在请求正文中发送。

相关问题