1 В избранное 0 Ответвления 0

OSCHINA-MIRROR/masx200-the-way-to-go_ZH_CN

Присоединиться к Gitlife
Откройте для себя и примите участие в публичных проектах с открытым исходным кодом с участием более 10 миллионов разработчиков. Приватные репозитории также полностью бесплатны :)
Присоединиться бесплатно
Клонировать/Скачать
twitter_status_json.go 805
Копировать Редактировать Web IDE Исходные данные Просмотреть построчно История
sanshan Отправлено 13.08.2017 09:14 30fe7a7
// twitter_status_json.go
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
)
type Status struct {
Text string
}
type User struct {
Status Status
}
func main() {
/* perform an HTTP request for the twitter status of user: Googland */
res, _ := http.Get("http://twitter.com/users/Googland.json")/*http://twitter.com/users/Googland.json页面不存在了*/
/* initialize the structure of the JSON response */
user := User{Status{""}}
/* unmarshal the JSON into our structures */
temp, _ := ioutil.ReadAll(res.Body)
body := []byte(temp)
json.Unmarshal(body, &user)
fmt.Printf("status: %s", user.Status.Text)
}
/* Output:
status: Robot cars invade California, on orders from Google:
Google has been testing self-driving cars ... http://bit.ly/cbtpUN http://retwt.me/97p
*/

Опубликовать ( 0 )

Вы можете оставить комментарий после Вход в систему

1
https://api.gitlife.ru/oschina-mirror/masx200-the-way-to-go_ZH_CN.git
git@api.gitlife.ru:oschina-mirror/masx200-the-way-to-go_ZH_CN.git
oschina-mirror
masx200-the-way-to-go_ZH_CN
masx200-the-way-to-go_ZH_CN
master