View previous topic :: View next topic |
Author |
Message |
cnecrea Voice
Joined: 08 Oct 2022 Posts: 3
|
Posted: Sat Nov 26, 2022 8:13 am Post subject: Unable to parse json, I need some help please |
|
|
Hi there,
I am unable to parse json from http://api.ipregistry.co
The json output is like:
Code: |
{
"security": {
"is_abuser": false,
"is_attacker": false,
"is_bogon": false,
"is_cloud_provider": false,
"is_proxy": false,
"is_relay": false,
"is_tor": false,
"is_tor_exit": false,
"is_vpn": false,
"is_anonymous": false,
"is_threat": false
}
}
|
And this is a part of my TCL. Can some one help me with this, please? I'll appreciate a lot
Code: |
# json parse
proc getjson {get data} {
set parse [::json::json2dict $data]
set return ""
foreach {name info} $parse {
if {[string equal -nocase $name $get]} {
set return $info
break;
}
}
return $return
}
# process check proxy
proc proxy_check {ip} {
global getjson
set link "http://api.ipregistry.co/$ip?key=s1nr112dyxmw3oy9"
set ipq [http::config -useragent "lynx"]
set ipq [::http::geturl $link]
set data [http::data $ipq]
::http::cleanup $ipq
set is_abuser [getjson "is_abuser" $data]
set is_attacker [getjson "is_attacker" $data]
set is_bogon [getjson "is_bogon" $data]
set is_cloud_provider [getjson "is_cloud_provider" $data]
set is_proxy [getjson "is_proxy" $data]
set is_relay [getjson "is_relay" $data]
set is_tor [getjson "is_tor" $data]
set is_tor_exit [getjson "is_tor_exit" $data]
set is_vpn [getjson "is_vpn" $data]
set is_anonymous [getjson "is_anonymous" $data]
set is_threat [getjson "is_threat" $data]
|
|
|
Back to top |
|
 |
CrazyCat Revered One

Joined: 13 Jan 2002 Posts: 1108 Location: France
|
Posted: Sat Nov 26, 2022 1:53 pm Post subject: |
|
|
First, "global" is used for variables, not procedures.
And if you create a dict called parse, you must use the dict utilities:
Code: | proc getjson get data} {
set parse [::json::json2dict $data]
if {![dict exists $parse security $get]} {
return ""
} else {
return [dict get $parse security $get]
}
} |
_________________ https://www.eggdrop.fr - French IRC network
Offer me a coffee - Do not ask me help in PM, we are a community. |
|
Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|