c# accepts the json returned from the remote


foreword

I encountered a very stupid problem when I was doing a project. It is outrageous to record
that it is not the first time I have encountered it, nor is it the first time I have solved it. Every time I encounter it, I will forget how to solve it before. It turned out to be a very simple question...


c# accepts the json returned from the remote

1. The json data returned by the remote interface

{
    
    
  "code": 200,
  "data": [
    {
    
    
      "code": 200,
      "dataId": "de6ace6f-e902-42aa-9d15-9b2a67299869",
      "extras": {
    
    
        
      },
      "msg": "OK",
      "results": [
        {
    
    
          "label": "normal",
          "rate": 99.9,
          "scene": "porn",
          "suggestion": "pass"
        }
      ],
      "taskId": "imgMdlOkkS4TS6Cv79uNMCNf-1wShHj",
      "url": "http://dyh.lyk520dtf.top/public/static/image/function/sjmm.png"
    }
  ],
  "msg": "OK",
  "requestId": "E36EF381-0E94-583F-B15A-F9525207C4B1"
}

2. c# code receiving

//response_json:远程接口返回的json
JObject response_jobject = JObject.Parse(response_json);

//判断code是否正确
if (response_jobject["code"].ToString() != "200") return false;
if (response_jobject["data"][0]["results"][0]["label"].ToString() != "normal") return false;

return true;

Pay attention to the position of adding 0. If you don’t add it, you will report an error if you miss one. I have been looking for me for a long time.
insert image description here


Guess you like

Origin blog.csdn.net/lyk520dtf/article/details/126999729