The use of json.parse in the JS part of wechat applet

73 views Asked by At

Development tools: wechat developer tools Windows 10 system.

Function Description: This is a part of the code that uploads a picture to the server and returns the image ID and URL. I print out the result of the process and put it in the second picture. Problem Description: I don't understand why the return value of successful upload needs to be processed with json.parse. I can't get the data directly through res.data.data.id. the developer tool will report an undefined error.

Specific introduction: according to my query data, JSON. Parse () method is generally a string when receiving server data, and converts the data into JavaScript objects. My own understanding is that according to the print result of line 861 in my second picture, I think the res.data I get is a string of data, which needs to be converted into a JSON object through json.parse before I can get data through the converted JSON object.

If my understanding is correct, I would like to ask if the back-end development can encapsulate res.data.data as a JSON object at the beginning, so that the front-end does not need the transformation steps( Because I used to get data through res.data.data, I was not sure about my understanding when I encountered this kind of error information for the first time. Thank you!

enter image description here

0

There are 0 answers