Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

React native How to get only one part of my JSON back to Axios API

[beginner in React Native] I am working on the authentification. I have my call to API. It sends me back a JSON object with all the infos login which is inside a string called "j".
How can I get only the the object inside the j and transform it into an object to use in my app?
thank you for your help !

import { createSlice, createAsyncThunk } from "@reduxjs/toolkit";
import axios from "axios";
import base64 from "react-native-base64";

export const loginUser = createAsyncThunk(
  'users/login',
  async ({ codeClient, userEmail, password }, thunkAPI) => {
    try 
      {
          const response = await axios(
            {
              method: "post",
              url: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
              params: 
                  {
      
                    AApplicationKey: "XXXXXXXXXXXXXXXXX",
                    AUriosCustomerID: "XXXXXXX",
                    AUserEmail: "XXXXXXXXXX",
                    AUserPwd: "XXXXXXXXX",
                  },
              headers: 
                  {
                    Authorization:
                      "Basic " +
                      base64.encode("xxxxxx" + ":" + "xxxxxxxxxxxxxxx"),
                    "Content-Type": "application/x-www-form-urlencoded",
                    Accept: "application/json",
                  }
            }
          );
          return JSON.parse(data.value[0].j);

      } catch (e) 
        {
          console.log('Error', e.response.data);
          return thunkAPI.rejectWithValue(e.response.data);
        }
  }
);```

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

In your code, the "const response" isn’t used.. you return "JSON.parse(data.value[0].j);"
So it can’t work.

Anyway your question is uncomplete without JSON answer is hard to say ^^

You should try

return JSON.parse(response.data.value[0].j);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading