示例#1
0
        public async Task <IDataTransferCollection <World> > GetWorlds()
        {
            var request = new WorldsRequest();

            using var response = await _http.SendAsync(request).ConfigureAwait(false);

            response.EnsureSuccessStatusCode();
            var json = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

            var context = response.Headers.GetCollectionContext();
            var list    = new List <World>();

            JsonConvert.PopulateObject(json, list, Json.DefaultJsonSerializerSettings);
            return(new DataTransferCollection <World>(list, context));
        }
示例#2
0
        public async Task <List <string> > GetAllJsonWorlds(bool indented)
        {
            var request = new WorldsRequest();

            using var response = await _http.SendAsync(request);

            using var responseReader = new StreamReader(await response.Content.ReadAsStreamAsync());
            using var jsonReader     = new JsonTextReader(responseReader);
            response.EnsureSuccessStatusCode();

            // API returns a JSON array but we want a List of JSON objects instead
            var array = await JToken.ReadFromAsync(jsonReader);

            return(array.Children <JObject>().Select(obj => obj.ToString(indented ? Formatting.Indented : Formatting.None)).ToList());
        }