1
Good evening. I’m trying to extract a json value from a certain page. Trial code:
package main
import (
"encoding/json"
"io/ioutil"
"net/http"
"fmt"
)
type Response struct {
proxy string `json:"proxy"`
ip string `json:"ip"`
port string `json:"port"`
connectionType string `json:"connectionType"`
asn string `json:"asn"`
isp string `json:"isp"`
resType string `json:"type"`
lastChecked int `json:"lastChecked"`
get bool `json:"get"`
post bool `json:"post"`
cookies bool `json:"cookies"`
referer bool `json:"referer"`
userAgent bool `json:"userAgent"`
city string `json:"city"`
state string `json:"state"`
country string `json:"country"`
randomUserAgent string `json:"randomUserName"`
requestsRemaining int `json:"requestsRemaining"`
}
func main() {
res, _ := http.Get("http://falcon.proxyrotator.com:51337/?apiKey=&country=BR")
body, _ := ioutil.ReadAll(res.Body)
var myStoredVariable Response
json.Unmarshal(body, &myStoredVariable)
fmt.Printf(myStoredVariable.proxy)
}
The code doesn’t return anything.
Reply JSON gives page:
{
"proxy": "170.80.14.253:57624",
"ip": "170.80.14.253",
"port": "57624",
"connectionType": "Residential",
"asn": "263603",
"isp": "Duplanet Internet E Informatica Ltda - Me",
"type": "elite",
"lastChecked": 1552253479,
"get": true,
"post": true,
"cookies": true,
"referer": true,
"userAgent": true,
"city": "Guaramirim",
"state": "SC",
"country": "BR",
"randomUserAgent": "Mozilla\/5.0 (Linux Android 4.1.2 DROID RAZR HD Build\/9.8.1Q-94) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/32.0.1700.99 Mobile Safari\/537.36",
"requestsRemaining": 15588
}
I need to get the value of proxy
, How can I do it?
Thank you.
Just one detail: you can convert JSON to Struct using https://mholt.github.io/json-to-go/. The fields must be public/exportable, with the initial uppercase, after all you are passing this struct to another library.
– Inkeliz