Join The Works program to have access to the most current content, and to be able to ask questions and get answers from Revelation staff and the Revelation community

At 19 FEB 2023 02:36:45PM Dave Sigafoos wrote:

I am working with the Json string at the bottom .. Now i haven't used Json before but seems pretty straight forward and using the HELP from OI.


rtn = Rti_Json(newJsonString,"Parse", jsonString)

This should take the 'existing' jsonString and create a newJsonString for parsing. Returning (rtn) a 0 if all went ok or an error number. I am right to this point? If I do this the newJsonString returns null and the rtn is 0.

If I try to GetValue like


rtn = Rti_Json(jsonString,"GetValue","city")

Shouldn't the rtn be Four Corners (from below)? INSTEAD i get a cJson line 1 non numeric value … OH My

Why and I getting non numeric ??? and shouldn't the code protect itself??

I would really appreciate some pointers on using the RTI_Json function.

tia

Dsig


{"ip": "xx.xxx.xx.xx",

  "type": "ipv4",

  "continent_code": "NA",

  "continent_name": "North America",

  "country_code": "US",

  "country_name": "United States",

  "region_code": "OR",

  "region_name": "Oregon",

  "city": "Four Corners",

  "zip": "97301",

  "latitude": 44.94348907470703,

  "longitude": -122.99376678466797,

  "location": {

    "geoname_id": 5727382,

    "capital": "Washington D.C.", "languages": [{

      "code": "en",

      "name": "English",

      "native": "English"

    }],

    "country_flag": "https://assets.ipstack.com/flags/us.svg",

    "country_flag_emoji": "\ud83c\uddfa\ud83c\uddf8",

    "country_flag_emoji_unicode": "U+1F1FA U+1F1F8",

    "calling_code": "1",

    "is_eu": false

  }

}

At 19 FEB 2023 05:13PM Dave Sigafoos wrote:

So trying to figure this out (have to stop doing things like this on the weekend :) I am using example 2 of the help for RTI_JSON.

I read in the json string (jString) from a file (see above json). When I do a parse like in the example I get a numeric string (error code from hell) of 1625496125648. I can't find any error OLE error codes in OI and search of google not really helping ..

oRec = RTI_JSON(jString, 'Parse')

So what am i doing wrong?


At 19 FEB 2023 05:13PM Dave Sigafoos wrote:

Post removed by author


At 19 FEB 2023 08:34PM Donald Bakke wrote:

So trying to figure this out (have to stop doing things like this on the weekend :) I am using example 2 of the help for RTI_JSON.

I read in the json string (jString) from a file (see above json). When I do a parse like in the example I get a numeric string (error code from hell) of 1625496125648. I can't find any error OLE error codes in OI and search of google not really helping ..

oRec = RTI_JSON(jString, 'Parse')

So what am i doing wrong?

The numeric string is the object that the Parse method is returning. You need to use this in your subsequent calls:

oRec = RTI_Json( jString, 'Parse' )

City = RTI_Json( oRec, 'GetValue', 'city' )

Don Bakke

SRP Computer Solutions, Inc.


At 19 FEB 2023 08:50PM Dave Sigafoos wrote:

Thanks for that Don … hard to do one line at a time when you can't do that :) Interesting that the call info says that "Parse" returns a 0 or an error code. This should probably be upgraded.

Thanks again

Dsig


At 19 FEB 2023 11:13PM Dave Sigafoos wrote:

thanks to don for pointer here and Karl and Carl for the pointer in the other question.

Here is a routine to use an IP and get the City, State, Lat and Long from that IP.

rtn = GpsFromIp(xx.xxx.xxx.xx) (replace with your ip)

rtn<1> = city

rtn<2> = state

rtn<3> = Latitude

rtn<4> = Longitude

Let me know if you have/find any problems ..

DSig


Function GPSfromIP(ipToCheck)



Declare Function RTI_JSON, OLE_GetWebpage, Get_Status

Declare Subroutine Set_Status, Msg



Equ True$ To 1

Equ False$ To 0

Equ Null$ To ""



If Not(Assigned(ipToCheck)) Or ipToCheck = Null$ Then

     Return Null$

end



// Get your account API key from https://ipstack.com/

APIKey = 'put your ipstack api key here'



// url to call

URL = 'http://api.ipstack.com/' : IPToCheck : '?access_key=' : APIKey

response = OLE_GetWebPage(url)



//Dump the raw response somewhere

OSWrite Response To 'd:\Temp\test.json'



// Parse the data and check

objJson = RTI_Json(response,"Parse")



error = Null$ 

If objJson # False$ Then

     Set_Status(0)

     city = rti_json(objJson, "GetValue", "city")

     If Get_Status(error) Then

          Msg(@Window, 'Error: ' : error)

          Set_Status(0) ;* reset

     End 

     state = RTI_Json(objJson, "GetValue", "region_code")

     If Get_Status(error) Then

          Msg(@Window, 'Error: ' : error)

          Set_Status(0) ;* reset

     End 

     latitude = RTI_Json(objJson, "GetValue", "latitude")

     If Get_Status(error) Then

          Msg(@Window, 'Error: ' : error)

          Set_Status(0) ;* reset

     End 

     longitude = RTI_Json(objJson, "GetValue", "longitude")

     If Get_Status(error) Then

          Msg(@Window, 'Error: ' : error)

          Set_Status(0) ;* reset

     End 

End Else 

	// The Parse failed

	msg(@WINDOW, 'Error, Parse of the Json returned failed')

End



rtnValue = city :@fm: state :@fm: Latitude :@fm: longitude



Return rtnValue


At 19 FEB 2023 11:48PM Donald Bakke wrote:

thanks to don for pointer here and Karl and Carl for the pointer in the other question.

Here is a routine to use an IP and get the City, State, Lat and Long from that IP.

rtn = GpsFromIp(xx.xxx.xxx.xx) (replace with your ip)

rtn<1> = city

rtn<2> = state

rtn<3> = Latitude

rtn<4> = Longitude

Let me know if you have/find any problems ..

DSig


Function GPSfromIP(ipToCheck)



Declare Function RTI_JSON, OLE_GetWebpage, Get_Status

Declare Subroutine Set_Status, Msg



Equ True$ To 1

Equ False$ To 0

Equ Null$ To ""



If Not(Assigned(ipToCheck)) Or ipToCheck = Null$ Then

     Return Null$

end



// Get your account API key from https://ipstack.com/

APIKey = 'put your ipstack api key here'



// url to call

URL = 'http://api.ipstack.com/' : IPToCheck : '?access_key=' : APIKey

response = OLE_GetWebPage(url)



//Dump the raw response somewhere

OSWrite Response To 'd:\Temp\test.json'



// Parse the data and check

objJson = RTI_Json(response,"Parse")



error = Null$ 

If objJson # False$ Then

     Set_Status(0)

     city = rti_json(objJson, "GetValue", "city")

     If Get_Status(error) Then

          Msg(@Window, 'Error: ' : error)

          Set_Status(0) ;* reset

     End 

     state = RTI_Json(objJson, "GetValue", "region_code")

     If Get_Status(error) Then

          Msg(@Window, 'Error: ' : error)

          Set_Status(0) ;* reset

     End 

     latitude = RTI_Json(objJson, "GetValue", "latitude")

     If Get_Status(error) Then

          Msg(@Window, 'Error: ' : error)

          Set_Status(0) ;* reset

     End 

     longitude = RTI_Json(objJson, "GetValue", "longitude")

     If Get_Status(error) Then

          Msg(@Window, 'Error: ' : error)

          Set_Status(0) ;* reset

     End 

End Else 

	// The Parse failed

	msg(@WINDOW, 'Error, Parse of the Json returned failed')

End



rtnValue = city :@fm: state :@fm: Latitude :@fm: longitude



Return rtnValue

I gather it is working for you?

You might want to initialize your variables before assigning them to the rtnValue variable. There is the possibility of a VNAV.

Don Bakke

SRP Computer Solutions, Inc.


At 20 FEB 2023 11:16AM Dave Sigafoos wrote:

Thanks Don .. that is why i put it out there for review and see if there were any problems …

It does seem to be working quite well Thanks. You are right .. usually i do initialize but seem to have missed that last night.

Have a great day

Dsig

View this thread on the Works forum...

  • third_party_content/community/commentary/forums_works/c654902033e6ae479872749f71944462.txt
  • Last modified: 2024/05/23 12:38
  • by 127.0.0.1