Chilkat JSON Object

This forum is for eXpress++ general support.
Message
Author
User avatar
unixkd
Posts: 565
Joined: Thu Feb 11, 2010 1:39 pm

Chilkat JSON Object

#1 Post by unixkd »

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
}
]
}

User avatar
PedroAlex
Posts: 229
Joined: Tue Feb 09, 2010 3:06 am

Re: Chilkat JSON Object

#2 Post by PedroAlex »

What is the problem?
Pedro Alexandre

User avatar
unixkd
Posts: 565
Joined: Thu Feb 11, 2010 1:39 pm

Re: Chilkat JSON Object

#3 Post by unixkd »

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



User avatar
Tom
Posts: 1170
Joined: Thu Jan 28, 2010 12:59 am
Location: Berlin, Germany

Re: Chilkat JSON Object

#4 Post by Tom »

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
Best regards,
Tom

"Did I offend you?"
"No."
"Okay, give me a second chance."

User avatar
PedroAlex
Posts: 229
Joined: Tue Feb 09, 2010 3:06 am

Re: Chilkat JSON Object

#5 Post by PedroAlex »

Can you Post the content PPS_TextView(cJS)
Pedro Alexandre

User avatar
unixkd
Posts: 565
Joined: Thu Feb 11, 2010 1:39 pm

Re: Chilkat JSON Object

#6 Post by unixkd »

Hi Tom

Worked PERFECTLY !!!

I cannot thank you enough, you are great

Joe

User avatar
Tom
Posts: 1170
Joined: Thu Jan 28, 2010 12:59 am
Location: Berlin, Germany

Re: Chilkat JSON Object

#7 Post by Tom »

Hi, Joe.

Great to hear! :)

Chilkat is excellent work, just like eXpress++.
Best regards,
Tom

"Did I offend you?"
"No."
"Okay, give me a second chance."

User avatar
unixkd
Posts: 565
Joined: Thu Feb 11, 2010 1:39 pm

Re: Chilkat JSON Object

#8 Post by unixkd »

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:

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
See error screen here:

Image
Attachments
UploadError.png
UploadError.png (19.91 KiB) Viewed 2954 times

skiman
Posts: 1185
Joined: Thu Jan 28, 2010 1:22 am
Location: Sijsele, Belgium
Contact:

Re: Chilkat JSON Object

#9 Post by skiman »

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.
Best regards,

Chris.
www.aboservice.be

User avatar
unixkd
Posts: 565
Joined: Thu Feb 11, 2010 1:39 pm

Re: Chilkat JSON Object

#10 Post by unixkd »

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 ?

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
Thanks

Joe

Post Reply