0

I am trying to access object filed values that are passed from twig to javascript.

 <a href data-user_data="{{ users|json_encode }}">

With:

var userData = $(this).data('user_data');

var myJSON = JSON.stringify(userData);

returning

{}

Tried:

var myJSON = JSON.parse(subscriptionData);

Got:

Uncaught SyntaxError: Unexpected token o in JSON at position 1

Non of the posts from the site did not help..

7
  • What does users or users|json_encode look like? Commented Nov 19, 2020 at 17:45
  • users returns object but users|json_encode is empty. Can not figure out why is that? @mtsknn Commented Nov 19, 2020 at 18:02
  • Because it is an object with only private properties? (just a guess) Commented Nov 19, 2020 at 18:13
  • 1
    Or implement jsonserializable Commented Nov 19, 2020 at 18:19
  • 1
    Ah, I knew there was something like that, but couldn't find it back, thx @DarkBee Commented Nov 19, 2020 at 18:27

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.