Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC:

JSON object behaviour in populateObjects 16 Sep 2013 09:48 #11102

for some unknown reason to me, the code in the function populateObjects:
		if (!empty($item->my_json_object))
		{
			$registry = new JRegistry;
			$registry->loadString($item->my_json_object);
			$item->my_json_object = new JObject($registry->toObject());
		}

return an empty object when I call directly the $model->getItem()

if I use the simple json_decode, it always perfectly works:
		if (!empty($item->my_json_object) AND is_string($item->my_json_object))
		{
			$item->my_json_object = json_decode($item->my_json_object);
		}

Please Log in or Create an account to join the conversation.

JSON object behaviour in populateObjects 23 Sep 2013 17:53 #11154

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 986
Fixed since 2.6
$item->my_json_object = new JObject($registry->toObject());

To:
$item->my_json_object = $registry->toObject();

Simple...
Coding is now a piece of cake
The following user(s) said Thank You: Tomaselli

Please Log in or Create an account to join the conversation.

JSON object behaviour in populateObjects 27 Sep 2013 11:24 #11198

Thanks for the fix.
I noticed a little bug when the function populateObjects is called again (for example when you call the function getForm).
In this situation the function populateObjects will overwrite the JSON object and the data will be deleted, to avoid that afurther check should be added:

Original jcook 2.6:
		if (!empty($item->my_json_obejct))
		{
			$registry = new JRegistry;
			$registry->loadString($item->my_json_obejct);
			$item->my_json_obejct = $registry->toObject();
		}

Modified:
		if (!empty($item->my_json_obejct) AND is_string($item->my_json_obejct)) /* hack */
		{
			$registry = new JRegistry;
			$registry->loadString($item->my_json_obejct);
			$item->my_json_obejct = $registry->toObject();
		}
The following user(s) said Thank You: admin

Please Log in or Create an account to join the conversation.

JSON object behaviour in populateObjects 27 Sep 2013 11:28 #11199

I'm also thinking that function populateObejcts should be called just ONCE on the same Item (and it is called more than once), shouldn't be added a static variable to check that?

Please Log in or Create an account to join the conversation.

JSON object behaviour in populateObjects 07 Oct 2013 00:19 #11303

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 986
Fixed now.
Coding is now a piece of cake
The following user(s) said Thank You: Tomaselli

Please Log in or Create an account to join the conversation.

JSON object behaviour in populateObjects 08 Oct 2013 07:58 #11328

thank you

Please Log in or Create an account to join the conversation.

  • Page:
  • 1
Time to create page: 0.066 seconds
  I still don't believe he can really be human to do all this ! From all of the forums that I've ever participated in this is certainly the one that most encapsulates the feeling of being truly open source where everyone's opinions and contributions can and will shape the development of the service! It's truly awesome! Hope you enjoy cooking and look forward to reading and contributing to any of the editorial work that you proposed too!! Thanks
Gez (audibleid - JED)

Get Started