NetTalk Central

Author Topic: json Support?  (Read 2908 times)

debzidoodle

  • Jr. Member
  • **
  • Posts: 98
    • View Profile
    • Email
json Support?
« on: May 22, 2014, 04:02:04 PM »
Hi Bruce

What support for json parsing does NetTalk (or any other utility) have?   I need reading of json more than writing...  here is an example of some data that I need to parse

Code: [Select]
Content-Type: application/json
{
"totalCount":25,
"offSet":0,
"limit":10,
"results":[
    {
        "comments":null,
        "statusHistory":null,
        "serviceType":"Tow",
        "coverage":null,
        "dispatchRequestNumber":"463798552",
        "urgency":null,
        "referenceNumber":null,
        "poNumber":"245711363",
        "problem":null,
        "equipment":
            {
                "type":"Light Duty Flatbed",
                "equipmentId":null
            },
        "receivedTime":"2013-11-11T16:14:59Z",
        "acceptedTime":"2013-11-11T16:14:57Z",
        "currentStatus":
           {
               "code":"0",
               "description":"UNASSIGNED",
               "eta":0,
               "reason":null,
               "reasonCode":0,
               "source":null,
               "extJobId":null,
               "latitude":0.0,
               "longitude":0.0,
               "statusTime":"0001-01-01T00:00:00",
               "driverId":0,
               "reportedBy":"USER"
             },
        "vehicle":
           {
               "vin":null,
               "year":"2011",
               "state":null,
               "make":"All Wheel Drive Equip.",
               "mileage":0,
               "model":"NULL",
               "color":"Unknown",
               "plate":null,
               "VehicleType":null,
               "driveTrainType":null,
               "fuelType":null
            },
        "disablementLocation":
            {
               "contactInfo":
                    {
                       "callbackNumber":null,
                       "name":"HOME 1",
                       "phone":null
                    },
                "dropInstructions":null,
                "garageClearanceHeight":null,
                "garageLevel":null,
                "isDriverWithVehicle":true,
                "nightDropOff":false,
                "parked":false,
                "address1":"422 North St",
                "address2":null,
                "crossStreet":null,
                "landmark":null,
                "locationType":null,
                "city":"Randolph",
                "poi1":null,
                "poi2":null,
                "state":"MA",
                "postalCode":"02368",
                "lat":42.1758751377985,
                "lng":-71.0348727425857
            },
        "towDestination":
            {
                "contactInfo":
                   {
                       "callbackNumber":null,
                       "name":"TOW TO",
                       "phone":""
                    },
                "nightDropOff":false,
                "address1":null,
                "address2":null,
                "crossStreet":null,
                "landmark":"",
                "locationType":"Dealership",
                "city":"DEDHAM",
                "poi1":null,
                "poi2":null,
                "state":"MA",
                "postalCode":null,
                "lat":42.24903717041,
                "lng":-71.176467895508
            },
        "assignedDriver":null,
        "eta":"2013-11-11T17:14:57",
        "etaInMinutes":60,
        "revisedEta":"2013-11-11T17:29:57",
        "revisedEtaInMinutes":15,
        "etaRevisionCount":1,
        "responseTimeExtCount":0,
        "dispatcherContactNumber":null,
        "signatures":null
    }, .
       .
       .
       .
]
}

Thanks
Debra

Djordje Radovanovic

  • Full Member
  • ***
  • Posts: 237
    • View Profile
Re: json Support?
« Reply #1 on: May 22, 2014, 10:06:50 PM »
Some kind of support for JSon is integrated in Clarion 9.1 but I have never use it.

Best regards,

Djole

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11191
    • View Profile
Re: json Support?
« Reply #2 on: May 23, 2014, 03:22:10 AM »
Hi Debra,

I have some JSON classes which Dries has written, but I haven't folded them into the shipping NetTalk stuff yet. It's fairly high on my list.

cheers
Bruce

debzidoodle

  • Jr. Member
  • **
  • Posts: 98
    • View Profile
    • Email
Re: json Support?
« Reply #3 on: May 23, 2014, 04:11:41 AM »
Thanks Bruce, my vote is the sooner the better  ;)  My project would be sooo much easier with a utility. 

kevin plummer

  • Hero Member
  • *****
  • Posts: 1195
    • View Profile
    • Production Accounting and Software Payroll
Re: json Support?
« Reply #4 on: March 01, 2015, 10:54:11 PM »
Hi Bruce,

I need to post some JSON to a web API.

From their docs:

curl -H "Content-Type: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d "{\"to\":\"$RECIPIENT_NUMBER\", \"body\":\"Hello!\"}" \
"https://api.telstra.com/v1/sms/messages"

I'm trying to post the JSON data exactly as it is shown above but the website is returning "Unsupported Header Value"

Also tried:

poststring= '<123>"to":"04xx940786","body":"SMS Unlock Test!"<125>'

ThisWebClient.Post(Clip(PostURL), Clip(PostString))

I'm not really sure if it is the JSON or something else in the header...

Cheers,

Kevin
   


Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11191
    • View Profile
Re: json Support?
« Reply #5 on: March 01, 2015, 11:49:10 PM »
Hi Kevin;

did you set the content type?

ThisWebClient.ContentType = 'application/json'

Cheers
Bruce

kevin plummer

  • Hero Member
  • *****
  • Posts: 1195
    • View Profile
    • Production Accounting and Software Payroll
Re: json Support?
« Reply #6 on: March 02, 2015, 03:48:07 AM »
Yes

ThisWebClient.ContentType = 'application/json'
AuthStr = 'Bearer XXXnmv0OtrIjAB7AEGg4osIhsC9Z'
ThisWebClient.Authorization = clip(AuthStr)
PostString = '<123>"to":"04xxx40786","body":"SMS Unlock Test!"<125>'
PostURL = 'https://api.telstra.com/v1/sms/messages'  !

415 Unsupported Media Type   API does not support the requested content type

I did a bit more digging and it didn't like the default Accept header - that needed to be 'application/json' as well.

It now works.

Thanks,

Kevin

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11191
    • View Profile
Re: json Support?
« Reply #7 on: March 03, 2015, 01:24:17 AM »
Excellent tip!