S
S
Sergey Zolotarev2022-01-19 13:01:11
AJAX
Sergey Zolotarev, 2022-01-19 13:01:11

How to correctly read data fragments from arrays inside an array from JSON Response and not only in the interface?

Good afternoon!

I recently implemented a web service that generates lists of empty and available data attributes in JSON format, and the client side of the site reads them. And the lists are combined into one response body and its initial version after the service is started: [["test"],"DBA Service Error!"]

What array values ​​mean this or that fragment (each fragment uses data from various DBMS used in the project)?:


  • The first value consists of an array with empty data attributes.
  • And the second one is also from the array, but responsible for the list of non-empty available attributes. But you won't see an array, since there is no such list in one of the DBMS! But you will see the error I implemented from its essence.



In the client side, I implemented a separate React component that reads the same response, and the compiler brought me this surprise:
TypeError: Cannot read properties of null (reading '1')


In the code, I implemented reading and handling errors from each fragment in the response if there are failures on the used DBMS servers or there is simply no data there. The problem itself touched the list of empty attributes and the component does not work because of this. How to solve this problem? The code of the problematic component is in the comments to this question and thank you in advance!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question