Chilkat JSON Object
Chilkat JSON Object
Hi ALL
I have a requirement to generate data according to the JSON format below. I am using Chilkat JSON object class but finding it difficult. Anybody with solution will be greatly appreciated. Note I am using Xbase++ 1.9
Thanks
Joe
Example request:
{
"theatre": {
"name": "Megaplex",
"address": "24 High Street, London SE20 7QU",
"timezone": "Europe/London",
},
"sessions" : [
{
"sessionId" : "sessionIdOne",
"sessionTime": "2018-04-17T18:25:00",
"timezone": "Europe/London",
"screen" : "Gold Class 3",
"screenNumber" : 7,
"screenCapacity" : 250,
"film" : {
"id" : "someIdaFilmId",
"name" : "Some Film",
"movieXchangeId" : "e98de96d-9f47-47bf-b345-a880eb711caa",
"maccsboxFilmId" : "1011.140",
"distributorId" : "45",
"distributorName" : "Paramount"
},
"details": {
"displayFormat" : "3D,IMAX",
"duration": 150,
"languages" : ["EN"],
"subtitles" : ["DE"],
"soundFormat" : "THX",
"seating" : "4DX",
"showType" : "01"
},
"salesByTicketType" : [
{
"ticketType": "adult",
"ticketPrice": 1250,
"admits": 55,
"complimentaryAdmits": 4,
"revenueGross" : 68750,
"revenueNet" : 59000,
"tax" : 9750
},
{
"ticketType": "child",
"ticketPrice": 950,
"admits": 7,
"complimentaryAdmits": 0,
"revenueGross" : 6650,
"revenueNet" : 5800,
"tax" : 850
}
],
"approvedForBilling": false
}
]
}
I have a requirement to generate data according to the JSON format below. I am using Chilkat JSON object class but finding it difficult. Anybody with solution will be greatly appreciated. Note I am using Xbase++ 1.9
Thanks
Joe
Example request:
{
"theatre": {
"name": "Megaplex",
"address": "24 High Street, London SE20 7QU",
"timezone": "Europe/London",
},
"sessions" : [
{
"sessionId" : "sessionIdOne",
"sessionTime": "2018-04-17T18:25:00",
"timezone": "Europe/London",
"screen" : "Gold Class 3",
"screenNumber" : 7,
"screenCapacity" : 250,
"film" : {
"id" : "someIdaFilmId",
"name" : "Some Film",
"movieXchangeId" : "e98de96d-9f47-47bf-b345-a880eb711caa",
"maccsboxFilmId" : "1011.140",
"distributorId" : "45",
"distributorName" : "Paramount"
},
"details": {
"displayFormat" : "3D,IMAX",
"duration": 150,
"languages" : ["EN"],
"subtitles" : ["DE"],
"soundFormat" : "THX",
"seating" : "4DX",
"showType" : "01"
},
"salesByTicketType" : [
{
"ticketType": "adult",
"ticketPrice": 1250,
"admits": 55,
"complimentaryAdmits": 4,
"revenueGross" : 68750,
"revenueNet" : 59000,
"tax" : 9750
},
{
"ticketType": "child",
"ticketPrice": 950,
"admits": 7,
"complimentaryAdmits": 0,
"revenueGross" : 6650,
"revenueNet" : 5800,
"tax" : 850
}
],
"approvedForBilling": false
}
]
}
Re: Chilkat JSON Object
I am using the code below to generate the template but not getting the desired result
Code: Select all
Function NumeroJsonTemplate()
Local json := CreateObject('Chilkat_9_5_0.JsonObject')
json:EmitCompact := 0
success := json:UpdateString("theatre.name", "Megaplex")
success := json:UpdateString("theatre.address", "24 High Street) London SE20 7QU")
success := json:UpdateString("theatre.timezone", "Europe/London")
success := json:UpdateString("sessions.xyz[0].Name","myName")
success := json:UpdateString("sessions.sessionId" , "sessionIdOne")
success := json:UpdateString("sessions.sessionTime", "2018-04-17T18,25,00")
success := json:UpdateString("sessions.timezone", "Europe/London")
success := json:UpdateString("sessions.screen" , "Gold Class 3")
success := json:UpdateInt("sessions.screenNumber" , 7)
success := json:UpdateInt("sessions.screenCapacity" , 250)
success := json:UpdateString("film.id" , "someIdaFilmId")
success := json:UpdateString("film.name" , "Some Film")
success := json:UpdateString("film.movieXchangeId" , "e98de96d-9f47-47bf-b345-a880eb711caa")
success := json:UpdateString("film.maccsboxFilmId" , "1011.140")
success := json:UpdateString("film.distributorId" , "45")
success := json:UpdateString("film.distributorName" , "Paramount")
success := json:UpdateString("details.displayFormat" , "3D)IMAX")
success := json:UpdateInt("details.duration", 150)
success := json:UpdateString("details.languages" , "EN")
success := json:UpdateString("details.subtitles" , "DE")
success := json:UpdateString("details.soundFormat" , "THX")
success := json:UpdateString("details.seating" , "4DX")
success := json:UpdateString("details.showType" , "01")
success := json:UpdateString("SalesByTicketType.ticketType", "adult")
success := json:UpdateInt("SalesByTicketType.ticketPrice", 1250)
success := json:UpdateInt("SalesByTicketType.admits", 55)
success := json:UpdateInt("SalesByTicketType.complimentaryAdmits", 4)
success := json:UpdateInt("SalesByTicketType.revenueGross" , 68750)
success := json:UpdateInt("SalesByTicketType.revenueNet" , 59000)
success := json:UpdateInt("SalesByTicketType.tax" , 9750)
success := json:UpdateString("SalesByTicketType.ticketType", "child")
success := json:UpdateInt("SalesByTicketType.ticketPrice", 950)
success := json:UpdateInt("SalesByTicketType.admits", 7)
success := json:UpdateInt("SalesByTicketType.complimentaryAdmits", 0)
success := json:UpdateInt("SalesByTicketType.revenueGross" , 6650)
success := json:UpdateInt("SalesByTicketType.revenueNet" , 5800)
success := json:UpdateInt("SalesByTicketType.tax" , 850)
success := json:UpdateBool("approvedForBilling", 0)
cJS := json:Emit()
PPS_TextView(cJS)
Return nil
Re: Chilkat JSON Object
Just use the online tool to create Foxpro code for your JSON. It's just little work to transfer that into Xbase++ code:
https://tools.chilkat.io/jsonCreate
https://tools.chilkat.io/jsonCreate
Best regards,
Tom
"Did I offend you?"
"No."
"Okay, give me a second chance."
Tom
"Did I offend you?"
"No."
"Okay, give me a second chance."
Re: Chilkat JSON Object
Hi Tom
Worked PERFECTLY !!!
I cannot thank you enough, you are great
Joe
Worked PERFECTLY !!!
I cannot thank you enough, you are great
Joe
Re: Chilkat JSON Object
Hi, Joe.
Great to hear!
Chilkat is excellent work, just like eXpress++.
Great to hear!

Chilkat is excellent work, just like eXpress++.
Best regards,
Tom
"Did I offend you?"
"No."
"Okay, give me a second chance."
Tom
"Did I offend you?"
"No."
"Okay, give me a second chance."
Re: Chilkat JSON Object
Hi Tom
I need your help to finalise this assignment:
I need to upload the json content to the test server detail given to me below:
Hi Joe,
I’ve setup the credentials on our UAT server for development/testing:
URL: https://uat1.numero.co/mapi/1/sessions/ ... THEATRE_ID}
User: cenima-test
Pass: CenimaTest
For the {THEATRE_ID} you can use any alphanumeric string that identifies the theatre within your system.
Best Regards,
I use this program below but it resulted in an error:
See error screen here:

I need your help to finalise this assignment:
I need to upload the json content to the test server detail given to me below:
Hi Joe,
I’ve setup the credentials on our UAT server for development/testing:
URL: https://uat1.numero.co/mapi/1/sessions/ ... THEATRE_ID}
User: cenima-test
Pass: CenimaTest
For the {THEATRE_ID} you can use any alphanumeric string that identifies the theatre within your system.
Best Regards,
I use this program below but it resulted in an error:
Code: Select all
Function NumeroUpload()
Local oUpload := ChilkatActiveX("CHILKAT_UPLOAD")
oUpload:HostName := "https://uat1.numero.co"
oUpload:Path := "/mapi/1/sessions/cenima-test/pepperoni-lekki202301"
oUpload:SSL := 1
oUpload:Password := "CenimaTest"
oUpload:Port := 443
oUpload:Login := "cenima-test"
oUpload:AddFileReference("File1","c:\pb\Numero.json")
nSuccess := oUpload:BeginUpload()
IF nSuccess <> 1
DC_Winalert( oUpload:LastErrorText,"Upload Begin")
Return nil
EndIf
DO WHILE oUpload:UploadInProgress == 1
//STR(oUpload:PercentUploaded) + "% " + STR(oUpload:NumBytesSent) + "/" + STR(oUpload:TotalUploadSize)
oUpload:SleepMs(200)
ENDDO
DC_Winalert(IF( oUpload:UploadSuccess <> 1, oUpload:LastErrorText,"Files uploaded!"),"Upload finish")
Return nil

- Attachments
-
- UploadError.png (19.91 KiB) Viewed 13268 times
Re: Chilkat JSON Object
Hi,
Do you need to upload the file itself or is this a request to a rest-api with the json in the body?
If you try the following:
URL: https://uat1.numero.co/mapi/1/sessions/8
The login and password is asked. With the login below you don't get any access?
User: cenima-test
Pass: CenimaTest
In a log of cases you can simply use loadfromurl(...) with parameters for the url, port, header, content.
Do you need to upload the file itself or is this a request to a rest-api with the json in the body?
If you try the following:
URL: https://uat1.numero.co/mapi/1/sessions/8
The login and password is asked. With the login below you don't get any access?
User: cenima-test
Pass: CenimaTest
In a log of cases you can simply use loadfromurl(...) with parameters for the url, port, header, content.
Re: Chilkat JSON Object
Hi Chris
Thanks for your response.
It is a request to a rest-api with the json in the body
I tried the code below, it return nil. Pls what am I doing wrongly and is there any means to get the error info ?
Thanks
Joe
Thanks for your response.
It is a request to a rest-api with the json in the body
I tried the code below, it return nil. Pls what am I doing wrongly and is there any means to get the error info ?
Code: Select all
#include "ASINET.CH"
Function NumeroUpload()
LOCAL cJsonText := Numero():New():JsonTemplate():cJsonStr
Local cWebContent := LoadFromUrl( "https://cenima-test:CenimaTest@uat1.numero.co/mapi/1/sessions/cenima-test/pepperoni-lekki202301", ;
INTERNET_DEFAULT_HTTPS_PORT, ;
INTERNET_COMMUNICATION_SECURE, ;
nil , ;
nil , ;
"POST", ;
cJsonText )
DC_ArrayView(cWebContent)
Return nil
Joe