It is currently Tue Sep 25, 2018 12:57 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: ComposeJSON with Floats
PostPosted: Wed Jul 11, 2018 8:56 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Tue Jun 08, 2004 10:29 am
Posts: 169
Location: Zurich, Switzerland
Hello Community

Before submitting as a bug report:

Code:
Define Latitude.f = 1.2345
Define Longitude.f = 6.7890

If CreateJSON(0)
   AddressNode = SetJSONObject(JSONValue(0))
   SetJSONFloat(AddJSONMember(AddressNode, "Latitude"), Latitude)
   SetJSONFloat(AddJSONMember(AddressNode, "Longitude"), Longitude)
   Debug ComposeJSON(0, #PB_JSON_PrettyPrint)
   FreeJSON(0)
EndIf

results in:
Code:
{
  "Latitude" : 1,234500051,
  "Longitude": 6,789000034
}

which gives errors when parsing e.g. in JavaScript (. needed instead of ,)

Is this a bug in the ComposeJSON-function?

It may be a locale setting thing, but there is no such setting in the JSON-lib. Maybe there is a workaround?

_________________
As you walk on by, Will you call my name? Or will you walk away?


Top
 Profile  
Reply with quote  
 Post subject: Re: ComposeJSON with Floats
PostPosted: Wed Jul 11, 2018 8:59 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Jun 22, 2003 7:43 pm
Posts: 250
Location: Germany, Homburg (Saar)
It's a point on both of my systems, on Linux and Windows.

_________________
Electronics, Crazy & Interesting Stuff, all that with text, image and sound? Click here!

The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.


Top
 Profile  
Reply with quote  
 Post subject: Re: ComposeJSON with Floats
PostPosted: Wed Jul 11, 2018 9:01 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Tue Jun 08, 2004 10:29 am
Posts: 169
Location: Zurich, Switzerland
I tested on MacOS (and need it for MacOS and Windows).
What is your default LOCALE setting?

_________________
As you walk on by, Will you call my name? Or will you walk away?


Top
 Profile  
Reply with quote  
 Post subject: Re: ComposeJSON with Floats
PostPosted: Wed Jul 11, 2018 9:26 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Tue Jun 08, 2004 10:29 am
Posts: 169
Location: Zurich, Switzerland
OK tested on Windows, seems to work, at least on my Win10 instance. Seems to be a MacOS bug?

_________________
As you walk on by, Will you call my name? Or will you walk away?


Top
 Profile  
Reply with quote  
 Post subject: Re: ComposeJSON with Floats
PostPosted: Wed Jul 11, 2018 9:31 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Tue Jun 08, 2004 10:29 am
Posts: 169
Location: Zurich, Switzerland
I did another test and read the current locale from my Mac system:
Code:
locale = CocoaMessage(0, 0, "NSLocale currentLocale", 0)
separator$ = PeekS(CocoaMessage(0, CocoaMessage(0, locale, "decimalSeparator", 0), "UTF8String"), -1, #PB_UTF8)
Debug separator$
which returns a . (point) which is correct.

So this seems to be a buggy implementation in the PureBasic ComposeJSON function?

_________________
As you walk on by, Will you call my name? Or will you walk away?


Top
 Profile  
Reply with quote  
 Post subject: Re: ComposeJSON with Floats
PostPosted: Wed Jul 11, 2018 10:06 am 
Offline
Administrator
Administrator

Joined: Fri May 17, 2002 4:39 pm
Posts: 13371
Location: France
moved to bug reports


Top
 Profile  
Reply with quote  
 Post subject: Re: ComposeJSON with Floats
PostPosted: Wed Jul 11, 2018 10:08 am 
Offline
Enthusiast
Enthusiast

Joined: Thu Aug 30, 2007 11:54 pm
Posts: 790
Location: right here
according to the documentation #PB_JSON_PrettyPrint output should be still readable for parsers so it shouldn't use locale settings for floating point formatting. But i don't get the comma, i get a dot (Linux x64).


Top
 Profile  
Reply with quote  
 Post subject: Re: ComposeJSON with Floats
PostPosted: Wed Jul 11, 2018 10:23 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Tue Jun 08, 2004 10:29 am
Posts: 169
Location: Zurich, Switzerland
According to my tests:
- it works on Windows and Linux (Linux tested by NicTheQuick) but not on MacOS
- it does not work with #PB_JSON_PrettyPrint
- it does not work without #PB_JSON_PrettyPrint

@Fred Thank you for looking at this!

_________________
As you walk on by, Will you call my name? Or will you walk away?


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye