WEBAPI返回值读取通用方法
WebAPI的返回结果通常都是如下格式
返回结果:
{"Result":{"ResponseStatus":{"ErrorCode":"","IsSuccess":"false","Errors":[{"FieldName":"","Message":"","DIndex":0}],"SuccessEntitys":[{"Id":"","Number":"","DIndex":0}],"SuccessMessages":[{"FieldName":"","Message":"","DIndex":0}],"MsgCode":""},"Id":"","Number":"","NeedReturnData":[{}]}}
通用解析方法:
一、解析成功内容
public static JArray APIResultSuccess(object retobj) { JObject jObject = JObject.Parse(JsonConvert.SerializeObject(retobj)); JArray array = new JArray(); array = jObject.Value<JObject>("Result").Value<JObject>("ResponseStatus").Value<JArray>("SuccessEntitys"); return array; }
二、解析失败内容
public static string APIResultErrors(object retobj) { JObject jObject = JObject.Parse(JsonConvert.SerializeObject(retobj)); JArray array = new JArray(); array = jObject.Value<JObject>("Result").Value<JObject>("ResponseStatus").Value<JArray>("Errors"); string strReturn = string.Empty; JObject jobRetBody ; foreach (var jErr in array) { jobRetBody = JObject.Parse(jErr.ToString()); strReturn += jobRetBody["Message"].Value<string>(); } return strReturn; }
点赞
WEBAPI返回值读取通用方法
WebAPI的返回结果通常都是如下格式返回结果:{"Result":{"ResponseStatus":{"ErrorCode":"","IsSuccess":"false","Errors":[{"FieldName":"...
点击下载文档
本文2024-09-16 18:32:18发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-22795.html
您需要登录后才可以发表评论, 登录登录 或者 注册
最新文档
热门文章