NetTalk Central

Author Topic: possible parser issue with jFiles  (Read 3701 times)

JPMacDonald

  • Full Member
  • ***
  • Posts: 106
    • View Profile
    • Email
possible parser issue with jFiles
« on: July 01, 2015, 05:15:09 AM »
Hi Bruce,

Finally got the example working with Willie's original request and I apologize to him for hijacking that thread a bit.

A small oddity with the data has cropped up. I tried to append various pieces of the queue data to a text string and display it and unexpected line breaks occur which seem to be related to the last element in an json object.
Displaying this data causes the line breaks when using the "value" data:
 
"elements" : [
            {
               "distance" : {
                  "text" : "16.5 mi",
                  "value" : 26580
               },
               "duration" : {
                  "text" : "20 mins",
                  "value" : 1202
               },
               "status" : "OK"
            }
     ]

Processing this does not exhibit the line breaks:
notice the commas after the last value in the in each set which I don't think is a properly formatted json object

"elements" : [
            {
               "distance" : {
                  "text" : "16.5 mi",
                  "value" : 26580,
               },
               "duration" : {
                  "text" : "20 mins",
                  "value" : 1202,
               },
               "status" : "OK"
            }
     ]

So it seems the parser is adding a little something extra to the last field in an object.

Example attached.

Regards

Parker

[attachment deleted by admin]

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: possible parser issue with jFiles
« Reply #1 on: July 01, 2015, 10:32:35 PM »
Hi Parker,

So yeah, adding the , is not the solution - that would indeed make the json invalid.

The root problem you have is that you are parsing a "number" into a "string". So in the Json;

               "duration" : {
                  "text" : "20 mins",
                  "value" : 1202
               },


you can see that "value" has no bounding quotes. Since Json can include <13,10> characters, that implies that the 13,10 is part of the value. (And it probably has a leading space as well)

comapre it to this json;

               "duration" : {
                  "text" : "20 mins",
                  "value" :1202},


or this;

               "duration" : {
                  "text" : "20 mins",
                  "value" : "1202"
               },


But the point is that "value" is clearly a number (only) so spaces and 13,10 etc can be removed. If you read this into a _string_ then it treats it as a string, but if you read it into a LONG or REAL then it'll be treated as a number....

capiche?

cheers
Bruce


JPMacDonald

  • Full Member
  • ***
  • Posts: 106
    • View Profile
    • Email
Re: possible parser issue with jFiles
« Reply #2 on: July 02, 2015, 01:59:08 AM »
Capiche.

Grazie.

Parker