Welcome, Guest
Username: Password: Remember me

TOPIC: [FIXED] JSON object behaviour in populateObjects

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

  • Tomaselli
  • Tomaselli's Avatar
  • Offline
  • Elite Member
  • Posts: 293
  • Thank you received: 87
  • Karma: 46
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);
		}
The administrator has disabled public write access.

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

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
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 administrator has disabled public write access.
The following user(s) said Thank You: Tomaselli

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

  • Tomaselli
  • Tomaselli's Avatar
  • Offline
  • Elite Member
  • Posts: 293
  • Thank you received: 87
  • Karma: 46
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 administrator has disabled public write access.
The following user(s) said Thank You: admin

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

  • Tomaselli
  • Tomaselli's Avatar
  • Offline
  • Elite Member
  • Posts: 293
  • Thank you received: 87
  • Karma: 46
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?
The administrator has disabled public write access.

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

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
Fixed now.
Coding is now a piece of cake
The administrator has disabled public write access.
The following user(s) said Thank You: Tomaselli

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

  • Tomaselli
  • Tomaselli's Avatar
  • Offline
  • Elite Member
  • Posts: 293
  • Thank you received: 87
  • Karma: 46
thank you
The administrator has disabled public write access.
Time to create page: 0.074 seconds

Get Started