早上,
我需要从Web服务返回一条消息。以下是我的代码示例,我正在返回一个字符串。
[web method] public string CheckFeedSubmission() { string responseText = ""; try { //Stuff goes here responseText = "It Worked!" } catch (Exception ex) { responseText = "Opps wehave an error! Exception message:" + ex.Message; } return responseText ; }
我目前收到以下回应…
<string xmlns="http://tempuri.org/"/>
我理想上想返回类似
{"success" : true, "message" : "***Message Here***"}
我敢肯定,一旦我有了主意,就可以在需要时退还其他物品。这只是我需要解决的基础。
非常感谢所有帮助,在此先感谢:)
更新:刚发现这个…
return "{Message:'hello world'}"
我需要类似的东西吗
responseText = "{"success" : true, "message" : \"There has been an error. Message: " + ex.Message + "\"}"
用:
[WebMethod] [ScriptMethod(ResponseFormat = ResponseFormat.Json)]//Specify return format. public string CheckFeedSubmission() { string responseText = ""; try { //Stuff goes here responseText = "It Worked!" } catch (Exception ex) { responseText = "Opps wehave an error! Exception message:" + ex.Message; } return responseText ; }
返回的结果将类似于:
<string xmlns="http://tempuri.org/"/> {"success" : true, "message" : "***Message Here***"} </string>