Axios Json-Array - Error

Hi,

i have a mysql-DB, a php file for reading tables and axios to get the response.

//Variables
data: () => ({
users: [],
userid: 0
}),

With the following code:
axios.get(“ajaxfile.php”).then(function(response) {

   alert(response.data);
});

i get this result:

[{“id”:“1”,“username”:“Max”,“name”:“Mustermann”,“email”:“muster@muster.de”},{“id”:“2”,“username”:“Peter”,“name”:“Zeuss”,“email”:“zeuss@bla.de”}]

But i cant do it to transform in the variable “users”… i try "this.users=response.data but i doesnt work…

this is my table i will show the data…

  <tr>
    <th>Username</th>
    <th>Name</th>
    <th>Email</th>
  </tr>

  <tr v-for="user in users" :key="user.id">
    <td>{{ user.username }}</td>
    <td>{{ user.name }}</td>
    <td>{{ user.email }}</td>
  </tr>
</table>

What am I doing wrong? JSON.parse says it has invalid chars… (the brackets…)

Thanks

Jakan

Hey @Jakan, I ran a quick test on your output and I found the following:

Which means they are actually separated into 2 separate objects, if you want to assign the response.data to your this.user variable, you will need to access one of these objects by the following: response.data[0] or response.data[1]

Hi,

thanks for your reply.

if i make response.data[1] it is only the first sign in the json-Response (the bracket) --> “[”

Greetings