NetTalk Central
NetTalk Web Server => Web Server - Ask For Help => Topic started by: debzidoodle 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
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
-
Some kind of support for JSon is integrated in Clarion 9.1 but I have never use it.
Best regards,
Djole
-
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
-
Thanks Bruce, my vote is the sooner the better ;) My project would be sooo much easier with a utility.
-
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
-
Hi Kevin;
did you set the content type?
ThisWebClient.ContentType = 'application/json'
Cheers
Bruce
-
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
-
Excellent tip!