Backendless Support
 
Answered

Cannot get property from object

47756fc439d04f9ce6858ef3a71cd1571a13870805d145868b4ea016146cd743

Why it returns null when I try to get property? Is there any other way to get author field from single Meme object?

Best Answer
photo

So this is the structure of your array:

Element 0 : user object

Element 1: an array of Meme objects

So if you need to get "author" from the first element of the Meme array, you need to do the following:

  1. Get element 1 from "posts" > that will return an array
  2. Get element 1 from the result of the step above.

Regards,

Mark

Leave a Comment

Comments (11)

photo
1

Hi Timur,

You're retrieving the "author" property from the object at position 1 from "posts". What makes you think that an object at that index contains that property?

Mark

photo
1

Hi, Mark.Because, I set offset = 0. It means that the first item in "posts" would be author of current meme. Then I add 100 Memes to my array. I have atleast 10 objects in my Database (as you can see above). So, the second object in array would be one of Memes, and all this objects with that type have "author" field, as you can see

photo
1

I recommend adding a "print" block at the very end of the logic (right before return) and print out the "posts" value. Then check the log file (in the Files section, the /logging directory) to see what the variable contains.

photo
1

I don't understand what I do wrong. I can see any log in my logging file

  • Screen 1
  • This information is shared privately in spoiler and not visible!

And the log file:

  • Screen 2
  • This information is shared privately in spoiler and not visible!

I tried to user SERVER_CODE logger and it didn't work

photo
1

Try using the "print" block instead

photo
1

  • Log
  • This information is shared privately in spoiler and not visible!

photo
1

Could you paste it as text please?

photo
1

  • Log text
  • This information is shared privately in spoiler and not visible!

photo
1

Current log file

photo
1

So this is the structure of your array:

Element 0 : user object

Element 1: an array of Meme objects

So if you need to get "author" from the first element of the Meme array, you need to do the following:

  1. Get element 1 from "posts" > that will return an array
  2. Get element 1 from the result of the step above.

Regards,

Mark

photo
1

Thanks

photo