Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8733917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:44:42+00:00 2026-06-13T09:44:42+00:00

I want to deserialize JSON in WinRT and for example I am trying StackExchange

  • 0

I want to deserialize JSON in WinRT and for example I am trying StackExchange Api 2.1.

I have methods like this:

public static async Task<string> GetJsonString()
        {
            HttpClient client = new HttpClient();
            string url = @"https://api.stackexchange.com/2.1/answers?fromdate=1349913600&order=desc&min=20&sort=votes&site=stackoverflow";
            HttpResponseMessage response = await client.GetAsync(url);
            return await response.Content.ReadAsStringAsync();
        }

        public static async void ParseJson()
        {
            string responseText = await GetJsonString();

            DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(JsonResponse));
            JsonResponse root;
            using (MemoryStream stream = new MemoryStream(Encoding.Unicode.GetBytes(responseText)))
            {
                root = serializer.ReadObject(stream) as JsonResponse;
            }
        }

and these classes:

[DataContract]
class Answer
{
    [DataMember(Name = "question_id")]
    public int QuestionId { get; set; }

    [DataMember(Name = "answer_id")]
    public int AnswerId { get; set; }

    [DataMember(Name = "creation_date")]
    public int CreationDate { get; set; }

    [DataMember(Name = "last_edit_date")]
    public int LastEditDate { get; set; }

    [DataMember(Name = "last_activity_date")]
    public int LastActivityDate { get; set; }

    [DataMember(Name = "score")]
    public int Score { get; set; }

    [DataMember(Name = "community_owned_date")]
    public int CommunityOwnedDate { get; set; }

    [DataMember(Name = "is_accepted")]
    public bool IsAccepted { get; set; }

    [DataMember(Name = "owner")]
    public Owner Owner { get; set; }
}

[DataContract]
class Owner
{
    [DataMember(Name = "user_id")]
    public int UserId { get; set; }

    [DataMember(Name = "display_name")]
    public string DisplayName { get; set; }

    [DataMember(Name = "reputation")]
    public int Reputation { get; set; }

    [DataMember(Name = "user_type")]
    public string UserType { get; set; }

    [DataMember(Name = "profile_image")]
    public string ProfileImage { get; set; }

    [DataMember(Name = "link")]
    public string Link { get; set; }

    [DataMember(Name = "accept_rate")]
    public int? AcceptRate { get; set; }
}

[DataContract]
class JsonResponse
{
    [DataMember(Name = "items")]
    public IList<Answer> Answers { get; set; }

    [DataMember(Name = "quota_remaining")]
    public int QuotaRemaining { get; set; }

    [DataMember(Name = "quota_max")]
    public int QuotaMax { get; set; }

    [DataMember(Name = "has_more")]
    public bool HasMore { get; set; }
}

What I am doing wrong that in responseText I get chars like these:\b\0\0\0\0\0\0�ێ���_E�E�FfwW\r,���...?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T09:44:43+00:00Added an answer on June 13, 2026 at 9:44 am

    Your url seems to return compressed data, and HttpClient somehow doesn’t understand this. Below code fixes this:

    public static async Task<string> GetJsonString()
    {
        HttpClient client = new HttpClient();
        string url = @"https://api.stackexchange.com/2.1/answers?fromdate=1349913600&order=desc&min=20&sort=votes&site=stackoverflow";
        HttpResponseMessage response = await client.GetAsync(url);
    
        byte[] buf = await response.Content.ReadAsByteArrayAsync();
        GZipStream zipStream = new GZipStream(new MemoryStream(buf), CompressionMode.Decompress);
        StreamReader reader = new StreamReader(zipStream);
        return reader.ReadToEnd();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have all this JSON text that I want to deserialize (or something) into
I want to deserialize a JSON strin like this { status:1, since:1245626956', list:{ 1:{
I want to deserialize some XML that looks like this: XML: <bookings> <booking> <timeStart>2012/7/2
Ok I have a json coming in that looks like this: {count:xxx, important:[{...}]} All
I'm trying to deserialize JSON in this format: { data: [ { installed: 1,
I have a exception from lift-json when I want to deserialize a json string.
I have a json response like this { latitude: 30.4848, longitude: -70.5484 } Now
i have a Json, i want to deserialize and save it inside the property
I have JSON response from Facebook, which I don't want to deserialize into a
Want to run javascript function from parent window in child window Example I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.