NetTalk Central

Author Topic: NetWebServiceMethod - change JSON reply type  (Read 6619 times)

Thys

  • Sr. Member
  • ****
  • Posts: 311
    • View Profile
    • Incasu
    • Email
NetWebServiceMethod - change JSON reply type
« on: April 19, 2017, 10:04:09 AM »
Hi,

I have a string variable as a return value in a web service method that returns JSON. Under certain conditions I would like this value not to contain string quotes around it in the JSON result. I see that in the generated code when I change

jsonResults.append('content',p_web.AsciiToUtf(REG:content),json:String)

to

jsonResults.append('content',p_web.AsciiToUtf(REG:content),json:Literal)

the string quotes are not added. How can this be done without changing the generated code?

Thanks

Thys

  • Sr. Member
  • ****
  • Posts: 311
    • View Profile
    • Incasu
    • Email
Re: NetWebServiceMethod - change JSON reply type
« Reply #1 on: April 20, 2017, 01:17:04 AM »
An embed point per parameter after the append statement can definitely be helpful please...

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11298
    • View Profile
Re: NetWebServiceMethod - change JSON reply type
« Reply #2 on: May 07, 2017, 11:05:05 PM »
I sense you have an OMIT statement in the gleam of your eye....

Incidentally json:literal would not be the right equate to use there, rather you'd want one of

json:String                   EQUATE(1) !json literal types
json:Numeric                  EQUATE(2)
json:Object                   EQUATE(3)
json:Array                    EQUATE(4)
json:Boolean                  EQUATE(5)
json:Nil                      EQUATE(6)
or a new one;
json:Auto                EQUATE(7)


the last one selects an appropriate type based on the contents of the value.

I've added a template setting to the "Field" and "StringTheory" types though for build 9.27 though.

cheers
Bruce


Thys

  • Sr. Member
  • ****
  • Posts: 311
    • View Profile
    • Incasu
    • Email
Re: NetWebServiceMethod - change JSON reply type
« Reply #3 on: May 08, 2017, 01:14:59 AM »
Thanks Bruce, looking forward to the new build.

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11298
    • View Profile
Re: NetWebServiceMethod - change JSON reply type
« Reply #4 on: May 08, 2017, 06:59:07 AM »
It's up.
update jFiles at the same time.

cheers
Bruce

Thys

  • Sr. Member
  • ****
  • Posts: 311
    • View Profile
    • Incasu
    • Email
Re: NetWebServiceMethod - change JSON reply type
« Reply #5 on: May 15, 2017, 04:04:32 AM »
Hi Bruce.

I installed 9.27 today. See attached - there is only one option in the "JSON type" drop list. Is that correct? If so, what purpose does the drop list have with only one option?

Thys

Thys

  • Sr. Member
  • ****
  • Posts: 311
    • View Profile
    • Incasu
    • Email
Re: NetWebServiceMethod - change JSON reply type
« Reply #6 on: May 15, 2017, 04:29:56 AM »
Bruce,

I also now get this prototype error - see attached.I saw that the last parameter is just "Auto", I changed the source to "json:auto" but it seems like the method override doesn't exist.

Thys

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11298
    • View Profile
Re: NetWebServiceMethod - change JSON reply type
« Reply #7 on: May 16, 2017, 04:11:56 AM »
in Netweb.tpw
line circa 18686

replace the line
            #Prompt('JSON type',DROP('String,Numeric,Object,Array,Boolean,Null,Auto')),%MethodReturnJsonType,default('String')

with
            #Prompt('JSON type',DROP('String|Numeric|Object|Array|Boolean|Null|Auto')),%MethodReturnJsonType,default('String')

repeat for line 18691

sorry about that - fixed for the next build.

Bruce
« Last Edit: May 16, 2017, 04:25:37 AM by Bruce »

Thys

  • Sr. Member
  • ****
  • Posts: 311
    • View Profile
    • Incasu
    • Email
Re: NetWebServiceMethod - change JSON reply type
« Reply #8 on: May 16, 2017, 09:52:53 PM »
Thanks, looks good now.