Last active
June 7, 2016 10:17
-
-
Save aisrael/05153b9672978a4a7ceb4a7431b0a82b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type ApiResponse struct { | |
RawItems []json.RawMessage `json:"items"` | |
HasMore bool `json:"has_more"` | |
QuotaMax int `json:"quota_max"` | |
QuotaRemaining int `json:"quota_remaining"` | |
} | |
type Owner struct { | |
// ... | |
} | |
type Question struct { | |
// ... | |
} | |
func main() { | |
// perform HTTP request | |
decoder := json.NewDecoder(resp.Body) | |
var apiResp = new(ApiResponse) | |
err = decoder.Decode(&apiResp) | |
if err != nil { | |
log.Fatal(err) | |
os.Exit(1) | |
} | |
fmt.Printf("Has more? %v\n", apiResp.HasMore) | |
fmt.Printf("Quota max: %d\n", apiResp.QuotaMax) | |
fmt.Printf("Quota remaining: %d\n", apiResp.QuotaRemaining) | |
fmt.Printf("Unmarshaling %d items...\n", len(apiResp.RawItems)) | |
for _, item := range apiResp.RawItems { | |
var question = new(Question) | |
err = json.Unmarshal(item, &question) | |
fmt.Printf("Question id: %d\n", question.QuestionId) | |
fmt.Printf("Question owner: %s\n", question.Owner.DisplayName) | |
fmt.Printf("Question title: %s\n", question.Title) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment