本文整理匯總了Golang中json.Json類的典型用法代碼示例。如果您正苦於以下問題:Golang Json類的具體用法?Golang Json怎麽用?Golang Json使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Json類的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: parseSearchResults
func parseSearchResults(elem json.Json) *SearchResult {
result := new(SearchResult)
result.Name = elem.Get("from_user").String()
result.ProfileImageUrl = elem.Get("profile_image_url").String()
result.Tweet = elem.Get("text").String()
result.SentAt = elem.Get("created_at").String()
return result
}
示例2: GetMentions
/**
* GetMentions gets all mentions of you using the credentials
* saved in the Client provided.
*/
func GetMentions(client *Client) (statuses []Status, err os.Error) {
log.Stdout("Get Mentions\n")
// get json response from server
var jsonStrResponse string
var maxFetchCount = client.MaxFetchCount
if maxFetchCount == 0 {
maxFetchCount = DefaultMaxFetchCount
} // use a default
var form = map[string][]string{
"count": []string{strconv.Itoa(maxFetchCount)},
}
// send request
jsonStrResponse, err = send(URLMentions, "GET", form, client, "count="+strconv.Itoa(maxFetchCount))
if err != nil {
return nil, err
}
// parse json response
var resultObj json.Json
resultObj, err = parseJson(jsonStrResponse)
if err != nil {
return nil, err
}
// create status response
var i int
statuses = make([]Status, resultObj.Len())
log.Stdoutf("result count: %d", resultObj.Len())
for i = 0; i < len(statuses); i++ {
var elem = resultObj.Elem(i)
statuses[i] = *parseStatus(elem)
}
return
}
示例3: GetDirectMessages
/**
* GetDirectMessages gets all of your direct messages. It uses the credentials
* saved in the Client provided.
*/
func GetDirectMessages(client *Client) (statuses []Status, err os.Error) {
log.Stdout("Get Direct Messages\n")
// get json response from server
var jsonStrResponse string
var maxFetchCount = client.MaxFetchCount
if maxFetchCount == 0 {
maxFetchCount = DefaultMaxFetchCount
} // use a default
// send request
jsonStrResponse, err = send(URLDirectMessages+"?count="+strconv.Itoa(maxFetchCount), "GET", nil, client, "")
if err != nil {
return nil, err
}
// parse json response
var resultObj json.Json
//log.Stdout("response: %s", jsonStrResponse);
resultObj, err = parseJson(jsonStrResponse)
if err != nil {
return nil, err
}
// create status response
var i int
statuses = make([]Status, resultObj.Len())
log.Stdoutf("result count: %d", resultObj.Len())
for i = 0; i < len(statuses); i++ {
statuses[i] = *parseDirectMessage(resultObj.Elem(i))
}
return
}
示例4: GetUserTimeline
/**
* GetUserTimeline gets the user's timeline (provided by screenName) using the credentials
* saved in the Client provided.
*/
func GetUserTimeline(client *Client, screenName string) (statuses []Status, err os.Error) {
log.Stdout("Get User's Timeline\n")
// get json response from server
var jsonStrResponse string
var maxFetchCount = client.MaxFetchCount
if maxFetchCount == 0 {
maxFetchCount = DefaultMaxFetchCount
} // use a default
// send request
jsonStrResponse, err = send(URLUserTimeline+"?screen_name="+screenName+"&count="+strconv.Itoa(maxFetchCount), "GET", nil, client, "")
if err != nil {
return nil, err
}
// parse json response
var resultObj json.Json
//log.Stdout("response: %s", jsonStrResponse);
resultObj, err = parseJson(jsonStrResponse)
if err != nil {
return nil, err
}
// create status response
var i int
statuses = make([]Status, resultObj.Len())
log.Stdoutf("result count: %d", resultObj.Len())
for i = 0; i < len(statuses); i++ {
var elem = resultObj.Elem(i)
//log.Stdoutf("found status: %s\n", elem.Get("text").String());
statuses[i] = *parseStatus(elem)
}
return
}
示例5: parseStatus
// parseStatus converts a json obj into a twitter status.
func parseStatus(elem json.Json) *Status {
status := new(Status)
status.Text = elem.Get("text").String()
status.SentAt = elem.Get("created_at").String()
status.Tweeter = *parseUser(elem.Get("user"))
return status
}
示例6: DoSearch
/**
* DoSearch searches all status updates for a particular pattern.
*/
func DoSearch(client *Client, query string) (searchResults []SearchResult, err os.Error) {
log.Stdout("Do Search\n")
// get json response from server
var jsonStrResponse string
var maxFetchCount = client.MaxFetchCount
if maxFetchCount == 0 {
maxFetchCount = DefaultMaxFetchCount
} // use a default
query = http.URLEscape(query) // make query safe to travel in http body/url
var maxFetchCountStr = strconv.Itoa(maxFetchCount)
// send request
log.Stdoutf("max fetch count: %s\n", maxFetchCountStr)
var url = URLSearch + "?q=" + query + "&rpp=" + maxFetchCountStr
jsonStrResponse, err = send(url, "GET", nil, client, "")
if err != nil {
return nil, err
}
// parse json response
var resultObj json.Json
resultObj, err = parseJson(jsonStrResponse)
if err != nil {
return nil, err
}
// create status response
var i int
resultObj = resultObj.Get("results")
searchResults = make([]SearchResult, resultObj.Len())
log.Stdoutf("result count: %d", resultObj.Len())
for i = 0; i < len(searchResults); i++ {
var elem = resultObj.Elem(i)
searchResults[i] = *parseSearchResults(elem)
}
return
}
示例7: GetFriendsTimeline
/**
* GetFriendsTimeline gets the same timeline as Home does on the web. It uses the credentials
* saved in the Client provided.
*/
func GetFriendsTimeline(client *Client) (statuses []Status, err os.Error) {
log.Stdout("Get Friends Timeline\n")
jsonStrResponse, err := GetFriendsTimelineJson(client)
if err != nil {
return nil, err
}
// parse json response
var resultObj json.Json
//log.Stdout("response: %s", jsonStrResponse);
resultObj, err = parseJson(jsonStrResponse)
if err != nil {
return nil, err
}
// create status response
var i int
statuses = make([]Status, resultObj.Len())
log.Stdoutf("result count: %d", resultObj.Len())
for i = 0; i < len(statuses); i++ {
statuses[i] = *parseStatus(resultObj.Elem(i))
}
return
}
示例8: parseUser
// parseUser converts a json obj into a twitter user
func parseUser(elem json.Json) *User {
user := new(User)
user.ScreenName = elem.Get("screen_name").String()
user.Name = elem.Get("name").String()
user.Description = elem.Get("description").String()
user.Url = elem.Get("url").String()
user.ProfileImageUrl = elem.Get("profile_image_url").String()
user.Location = elem.Get("location").String()
user.FriendsCount, _ = strconv.Atoi(elem.Get("friends_count").String())
user.FollowersCount, _ = strconv.Atoi(elem.Get("followers_count").String())
user.ProfileBgColour = "#" + elem.Get("profile_background_color").String()
user.ProfileFgColour = "#" + elem.Get("profile_text_color").String()
user.ProfileLinkColour = "#" + elem.Get("profile_link_color").String()
user.ProfileBgImageUrl = elem.Get("profile_background_image_url").String()
user.ProfileBgImageTile = elem.Get("profile_background_tile").String() == "true"
return user
}