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 8507675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:56:14+00:00 2026-06-11T02:56:14+00:00

Okay I’ll try to be very specific with my problem right here. After some

  • 0

Okay I’ll try to be very specific with my problem right here. After some research i finally made my code work (kind of, because it doesn’t return the desired result). I’m currently using JSON.net and try to deserialize the following Json string which is a response for a twitter API.

[{"created_at":"2012-09-03T18:22:54Z","locations":[{"name":"Globales","woeid":1}],"trends":[{"query":"%2327CosasSobreMi","name":"#27CosasSobreMi","promoted_content":null,"url":"http:\/\/twitter.com\/search\/?q=%2327CosasSobreMi","events":null},{"query":"%23AskTravis","name":"#AskTravis","promoted_content":null,"url":"http:\/\/twitter.com\/search\/?q=%23AskTravis","events":null},{"query":"%23WhyDoPeopleThinkItsOkayTo","name":"#WhyDoPeopleThinkItsOkayTo","promoted_content":null,"url":"http:\/\/twitter.com\/search\/?q=%23WhyDoPeopleThinkItsOkayTo","events":null},{"query":"%22We%20%3C3%20Justin%22","name":"We \u003C3 Justin","promoted_content":null,"url":"http:\/\/twitter.com\/search\/?q=%22We%20%3C3%20Justin%22","events":null},{"query":"%22We%20Adore%20One%20Direction%22","name":"We Adore One Direction","promoted_content":null,"url":"http:\/\/twitter.com\/search\/?q=%22We%20Adore%20One%20Direction%22","events":null},{"query":"%22Stefan%20Is%20Elena's%20Humanity%22","name":"Stefan Is Elena's Humanity","promoted_content":null,"url":"http:\/\/twitter.com\/search\/?q=%22Stefan%20Is%20Elena's%20Humanity%22","events":null},{"query":"%22Eric%20Saade%20Come%20Back%20To%20Poland%22","name":"Eric Saade Come Back To Poland","promoted_content":null,"url":"http:\/\/twitter.com\/search\/?q=%22Eric%20Saade%20Come%20Back%20To%20Poland%22","events":null},{"query":"Hlavackova","name":"Hlavackova","promoted_content":null,"url":"http:\/\/twitter.com\/search\/?q=Hlavackova","events":null},{"query":"%22Serena%20Williams%22","name":"Serena Williams","promoted_content":null,"url":"http:\/\/twitter.com\/search\/?q=%22Serena%20Williams%22","events":null},{"query":"%22Kire%C3%A7burnu%20%C3%87akallar%C4%B1%22","name":"Kire\u00e7burnu \u00c7akallar\u0131","promoted_content":null,"url":"http:\/\/twitter.com\/search\/?q=%22Kire%C3%A7burnu%20%C3%87akallar%C4%B1%22","events":null}],"as_of":"2012-09-03T18:25:18Z"}]

Regular Json string containing objects and stuff… Except i don’t know what’s with the first “[,]” in the beginning and in the end, a friend pointed that out. Now i made some classes for that Json string:

public class Location
{
    private string _name;
    private int _woeid;

    public string name { get { return _name; } set { value = _name; } }
    public int woeid { get { return _woeid; } set { value = _woeid; } }
}

public class Trend
{
    private string _query, _name, _url;
    private object _promoted_content, _events;

    public string query { get { return _query; } set { value = _query; } }           
    public string name { get { return _name; } set { value = _name; } }
    public object promoted_content { get { return _promoted_content; } set { value = _promoted_content; } }
    public string url { get { return _url; } set { value = _url; } }
    public object events { get { return _events; } set { value = _events; } }

}

public class RootObject
{
    private List<Location> _locations;
    private List<Trend> _trends;
    private string created_at_, _as_of;

    public List<Trend> trends { get { return _trends; } set { value = _trends; } }         
    public string created_at { get { return created_at_;} set { value = created_at_; } }
    public string as_of { get { return _as_of ;} set { value = _as_of; } }
    public List<Location> locations { get { return _locations; } set { value = _locations; }}
}       

And the method I’m using to deserealize it is this one:

WebClient client = new WebClient();
Stream stream = client.OpenRead(@"https://api.twitter.com/1/trends/1.json");
StreamReader reader = new StreamReader(stream);
string nvm = reader.ReadToEnd();
try
{
  List<RootObject> content = JsonConvert.DeserializeObject<List<RootObject>>(JsonString);
}
catch (System.Exception message)
{
    throw;
}

I just can’t figure if my classes are wrong because the variable content is always Null and i can’t change the abstract definitions as im using Visual Studio 2005. Tried changing the Lists inside the classes but can’t make it work.

I’ve tried different methods with all the different responses here in StackOverflow but they all seem to either use some methods unavailable for me or the regular deserialization works for them.

  • 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-11T02:56:15+00:00Added an answer on June 11, 2026 at 2:56 am

    You don’t need any of these classes. Just use dynamic

    WebClient client = new WebClient();
    string json = client.DownloadString("https://api.twitter.com/1/trends/1.json");
    
    dynamic dynObj = JsonConvert.DeserializeObject(json);
    
    foreach (var item in dynObj)
    {
        foreach (var trend in item.trends)
        {
            Console.WriteLine("{0} - {1} - {2}",trend.query,trend.name,trend.url);
        }
    }
    

    EDIT

    Another version without dynamic

    var dynObj = (JArray)JsonConvert.DeserializeObject(json);
    foreach (var item in dynObj)
    {
        foreach (var trend in item["trends"])
        {
            Console.WriteLine("{0} - {1} - {2}",trend["query"],trend["name"],trend["url"]);
        }
    }
    

    EDIT2

    JArray dynObj = (JArray)JsonConvert.DeserializeObject(json);
    foreach (JObject item in dynObj)
    {
        foreach (JObject trend in item["trends"])
        {
            Console.WriteLine("{0} - {1} - {2}",trend["query"],trend["name"],trend["url"]);
        }
    }
    

    EDIT3

    for (int i = 0; i < dynObj.Count;i++)
    {
        for (int j = 0; j < ((JArray) dynObj[i]["trends"]).Count;j++ )
        {
            JObject trend = (JObject)((JArray)dynObj[i]["trends"])[j];
            Console.WriteLine("{0} - {1} - {2}", trend["query"], trend["name"], trend["url"]);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay, so I have the weirdest problem right now. My code is fine! It
Okay, so the answer to my question might not be the problem but here's
Okay, I'm reading about Linux kernel development and there are some code snippets using
Okay this question is very simple: I have a facebook page, and a website.
Okay, this is probably a very basic question; but, I'm just getting back in
Okay, I have GOT to be missing something totally rudimentary here. I have an
Okay, so this is a long long shot but here it goes... When IE
Okay so my question is this. Say I have a simple C++ code: #include
Okay, here's the rundown. I'm developing a video hosting site with PHP and jQuery
Okay, I have setup up a handler for a div click but for some

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.