I am working with twitter api trying to get json data from
http:
which is as follows:
{"as_of":1268069036,"trends":{"2010-03-08 17:23:56":[{"name":"Happy Women Day","query":"\"Happy Women Day\" OR \"Women Day\""},{"name":"#MusicMonday","query":"#MusicMonday"},{"name":"#MM","query":"#MM"},{"name":"Oscars","query":"Oscars OR #oscars"},{"name":"#nooffense","query":"#nooffense"},{"name":"Hurt Locker","query":"\"Hurt Locker\""},{"name":"Justin Bieber","query":"\"Justin Bieber\""},{"name":"Cmon","query":"Cmon"},{"name":"My World 2","query":"\"My World 2\""},{"name":"Sandra Bullock","query":"\"Sandra Bullock\""}]}}
My structures look like this:
type trend struct {
name string
query string
}
type trends struct {
id string
arr_of_trends []trend
}
type Trending struct {
as_of string
trends_obj trends
}
and then I parse JSON into a type variable Trending. I am very new to JSON, so my main task is to make sure that I have a data structure correctly configured to store the returned json data.
I write this in "Go" for a project for school. (This is not included in any specific task, I am just demonstrating something for a presentation in the language)
UPDATE: as per PeterSO comment I go on a regular route. Using:
Cur_Trends := new(Current)
//find proper json time-name
aoUnixTime, _, _ := os.Time()
// insert code to find and convert as_of Unix time to aoUnixTime
aoName := time.SecondsToUTC(aoUnixTime).Format(`"2006-01-02"`)
fmt.Printf("%s\n", aoName)
regexp_pattern := "/" + aoName + "/"
regex, _ := regexp.Compile(regexp_pattern);
cleaned_json := regex.ReplaceAllString(string(body2), "ntrends")
os.Stdout.WriteString(cleaned_json)
No changes are displayed. Am I setting a regular expression incorrectly? It seems that "Go" allows only one regular expression at a time ...
UPDATE:
/ "ntrends", "Unmarshaling" . json.Decode, ...
, : :
map[as_of:1.268176902e+09 trends:map[ntrends:[map[name:#nowplaying query:#nowplaying] map[name:#imtiredofseeing query:#imtiredofseeing] map[name:#iWillNever query:#iWillNever] map[name:#inmyfamily query:#inmyfamily] map[name:#raiseyourhandif query:#raiseyourhandif] map[name:#ripbig query:#ripbig] map[name:QVC query:QVC] map[name:#nooffense query:#nooffense] map[name:#RIPLaylaGrace query:#RIPLaylaGrace] map[name:Justin Bieber query:"Justin Bieber"]]]]
"... " ...