NetTalk Central

Author Topic: json format in post data  (Read 3519 times)

ntnewbies

  • Full Member
  • ***
  • Posts: 184
    • View Profile
    • Email
json format in post data
« on: August 16, 2021, 02:09:42 AM »
hi everyone

i am making an api call and i need to provide some json info inside the post data

postdata = st.getvalue()
posturl = 'api.testdata.payme'

net.post(posturl,postdata)


sample post data:

{
    "order" : {
        "amountOfMoney" : {
            "currencyCode" : "USD",
            "amount" : 2345
        },
        "customer" : {
            "merchantCustomerId" : "1234",
            "billingAddress" : {
                "countryCode" : "US"
            }
        }
    },
    "hostedCheckoutSpecificInput" : {
        "variant" : "testVariant",
        "locale" : "en_GB"
    }
}


usd, 234, 1234, US should be variables.
how do i put it inside string theory?

i have tried the following way but compiler gives error of misused of {{

st.setvalue('{order": {"amountOfMoney" : {"currencyCode" : "' & LOC:CurrencyCode & '","amount" : ' & LOC:Amount......&'}}'

regards,
Jason
nt11.53
c11




bshields

  • Sr. Member
  • ****
  • Posts: 392
    • View Profile
    • Inhabit
    • Email
Re: json format in post data
« Reply #1 on: August 16, 2021, 04:00:10 AM »
Hi Jason,

Use {{ to escape the single { in clarion code.

Don't do it for }

Regards
Bill

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: json format in post data
« Reply #2 on: August 16, 2021, 10:23:50 PM »
also, there's no need to move the string from the stringtheory object, to a (possibly too small) string. ie

postdata = st.getvalue()
posturl = 'api.testdata.payme'
net.post(posturl,postdata)

can be replaced with

posturl = 'api.testdata.payme'
net.post(posturl,st)

Cheers
Bruce

ntnewbies

  • Full Member
  • ***
  • Posts: 184
    • View Profile
    • Email
Re: json format in post data
« Reply #3 on: August 19, 2021, 10:17:25 PM »
thanks bill and bruce for the tip.

will try again.


jason