當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Json.Len方法代碼示例

本文整理匯總了Golang中json.Json.Len方法的典型用法代碼示例。如果您正苦於以下問題:Golang Json.Len方法的具體用法?Golang Json.Len怎麽用?Golang Json.Len使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在json.Json的用法示例。


在下文中一共展示了Json.Len方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: 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
}
開發者ID:tommed,項目名稱:GoogleGo-Twitter-Client,代碼行數:39,代碼來源:twitter.go

示例2: 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
}
開發者ID:tommed,項目名稱:GoogleGo-Twitter-Client,代碼行數:38,代碼來源:twitter.go

示例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
}
開發者ID:tommed,項目名稱:GoogleGo-Twitter-Client,代碼行數:36,代碼來源:twitter.go

示例4: 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
}
開發者ID:tommed,項目名稱:GoogleGo-Twitter-Client,代碼行數:40,代碼來源:twitter.go

示例5: 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
}
開發者ID:tommed,項目名稱:GoogleGo-Twitter-Client,代碼行數:28,代碼來源:twitter.go


注:本文中的json.Json.Len方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。