none
Jobject Query RRS feed

  • Question

  • How do I deserialize the response from the URL with Jobject or Jarray?  

    https://api.census.gov/data/2010/sf1?get=P0010001,H0120001,H0110001,H0110002,H0110003,H0110004&for=block%20group:1&in=state:02%20county:170%20tract:000101

    Monday, November 13, 2017 7:27 PM

Answers

  • Hello DDL19,

    Because the response data doesn't contain "key" property. you could deserialize the response by JArray . The following is a simple demo.

    string url = "https://api.census.gov/data/2010/sf1?get=P0010001,H0120001,H0110001,H0110002,H0110003,H0110004&for=block%20group:1&in=state:02%20county:170%20tract:000101";
    
                HttpWebRequest httpWeb =(HttpWebRequest)WebRequest.Create(url);
    
                Stream ws= httpWeb.GetResponse().GetResponseStream();
    
                StreamReader streamReader = new StreamReader(ws, Encoding.UTF8);
    
                string data = streamReader.ReadToEnd();
    
    
    
    
               var mJObj = JArray.Parse(data);
    
                foreach (var ss in mJObj)  
                {
                    foreach (var s in ss.Values()) {
                        Console.WriteLine(s);        
                    }
                    Console.WriteLine("-----------------");
                }

    Sincerely,

    Neil Hu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by DDL19 Tuesday, November 14, 2017 12:33 PM
    Tuesday, November 14, 2017 3:21 AM
    Moderator

All replies

  • Hello DDL19,

    Because the response data doesn't contain "key" property. you could deserialize the response by JArray . The following is a simple demo.

    string url = "https://api.census.gov/data/2010/sf1?get=P0010001,H0120001,H0110001,H0110002,H0110003,H0110004&for=block%20group:1&in=state:02%20county:170%20tract:000101";
    
                HttpWebRequest httpWeb =(HttpWebRequest)WebRequest.Create(url);
    
                Stream ws= httpWeb.GetResponse().GetResponseStream();
    
                StreamReader streamReader = new StreamReader(ws, Encoding.UTF8);
    
                string data = streamReader.ReadToEnd();
    
    
    
    
               var mJObj = JArray.Parse(data);
    
                foreach (var ss in mJObj)  
                {
                    foreach (var s in ss.Values()) {
                        Console.WriteLine(s);        
                    }
                    Console.WriteLine("-----------------");
                }

    Sincerely,

    Neil Hu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by DDL19 Tuesday, November 14, 2017 12:33 PM
    Tuesday, November 14, 2017 3:21 AM
    Moderator
  • In the same way as you can cook a car. 

    Serialization and Jobject have no relation in C#


    Success
    Cor


    Tuesday, November 14, 2017 3:43 AM