Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

Bug in returned JSON

 
Reply
   X-Cart forums > X-Cart 5 > Dev Questions (X-Cart 5)
 
Thread Tools Search this Thread
  #1  
Old 05-02-2017, 05:59 PM
 
OrangeBill OrangeBill is offline
    
Join Date: May 2017
Posts: 2
 

Exclamation Bug in returned JSON

Hi,
I believe I have found 2 issues in the json response for:
URL/admin.php?target=RESTAPI&_key=XXXXX'&_path=order&_ schema=complex


1 - the returned JSON spells "arrtibutes" instead of "attributes"
... "arrtibutes":[],"price":9.99,"weight":0.3,"quantity":6, ....

2 - if there are NO attributes, its shows as an array ie - surrounded by []
However, if there ARE attributes, it is not an array - missing the [ ]

... "arrtibutes":{"Color":"Yellow","Size":"S"},"price" :19.99,"weight":0.5,...

Can this be fixed?
__________________
Business 5.3.2.9
Rest API
Reply With Quote
  #2  
Old 05-03-2017, 04:01 AM
  qualiteam's Avatar 
qualiteam qualiteam is offline
 

X-Guru
  
Join Date: Dec 2010
Posts: 6,373
 

Default Re: Bug in returned JSON

Quote:
Originally Posted by OrangeBill
1 - the returned JSON spells "arrtibutes" instead of "attributes"
... "arrtibutes":[],"price":9.99,"weight":0.3,"quantity":6, ....

Thanks! I've reported this to the XC5 dev team:
https://bt.x-cart.com/view.php?id=47930

Quote:
Originally Posted by OrangeBill
2 - if there are NO attributes, its shows as an array ie - surrounded by []
However, if there ARE attributes, it is not an array - missing the [ ]

... "arrtibutes":{"Color":"Yellow","Size":"S"},"price" :19.99,"weight":0.5,...

Can this be fixed?

["Color":"Yellow","Size":"S"] is not a valid JSON. "[" and "]" can be used for plain lists only (like ["Color", "Size"]), so X-Cart converted its PHP array to a valid JSON object correctly.
__________________
Alex Solovev,
Qualiteam

---

User manual Video tutorials X-Cart FAQ

You are welcome to press "Thanks" button
if you find this post useful

Click here to learn how to apply patches

X-Cart Extensions
Reply With Quote
  #3  
Old 05-03-2017, 04:19 AM
 
OrangeBill OrangeBill is offline
    
Join Date: May 2017
Posts: 2
 

Default Re: Bug in returned JSON

Shouldn't the array be...
[{"Color":"Yellow","Size":"S"}],"price" :19.99,"weight":0.5,...

Inside brackets?
__________________
Business 5.3.2.9
Rest API
Reply With Quote
  #4  
Old 05-03-2017, 11:05 PM
  qualiteam's Avatar 
qualiteam qualiteam is offline
 

X-Guru
  
Join Date: Dec 2010
Posts: 6,373
 

Default Re: Bug in returned JSON

In PHP arrays elements may have custom keys:
PHP Code:
array("Color" => "Yellow""Size" => "S"

In JavaScript (JSON comes from there) arrays have no keys, so arrays with keys translate from PHP to JSON as objects:
Code:
{"Color":"Yellow", "Size":"S"}
There is nothing wrong in doing that and you won't get any benefits by wrapping the object into an extra array (that will always contain a single element only).
__________________
Alex Solovev,
Qualiteam

---

User manual Video tutorials X-Cart FAQ

You are welcome to press "Thanks" button
if you find this post useful

Click here to learn how to apply patches

X-Cart Extensions
Reply With Quote
Reply
   X-Cart forums > X-Cart 5 > Dev Questions (X-Cart 5)



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 04:25 PM.

   

 
X-Cart forums © 2001-2020