获取内容结果的代码
IRestResponse response = client.Execute(request);
var content = (string)JsonConvert.DeserializeObject(response.Content);
response.content
应返回此4 msg中的以太一个。
如果API返回其他内容怎么办?如何验证?
答案 0 :(得分:0)
检查内容:
if(content != "OK" && content != "INVALID_MESSAGE_ID" && content != "MESSAGE_NOT_FOUND" && content != "INTERNAL_ERROR") {
//Do some handling, like logging
}
或者:
switch(content) {
case "OK":
// Do something, when content is OK
break;
case "INVALID_MESSAGE_ID":
// Do something, when content is INVALID_MESSAGE_ID
break;
case "MESSAGE_NOT_FOUND":
// Do something, when content is MESSAGE_NOT_FOUND
break;
case "INTERNAL_ERROR":
// Do something, when content is INTERNAL_ERROR
break;
case default:
// Do something, if no case is matched
break;
}