This is my first time using json.net and I can't figure it out. Here is my code below.
// Constructor
    public MainPage()
    {
        InitializeComponent();
    }
    private void btnRefreshTweets_Click(object sender, RoutedEventArgs e)
    {
        string ServerURL = @"http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StateCityHighway_USA/MapServer/1/query?text=e&geometry=&geometryType=esriGeometryPoint&inSR=&spatialRel=esriSpatialRelIntersects&relationParam=&objectIds=&where=&time=&returnCountOnly=false&returnIdsOnly=false&returnGeometry=false&maxAllowableOffset=&outSR=&outFields=&f=json";
        WebClient webClient = new WebClient();
        webClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(webClient_DownloadStringCompleted);
        webClient.DownloadStringAsync(new Uri(ServerURL));
    }
    void webClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
    {
        if (e.Error != null)
        {
            return;
        }
        List<Attributes> tweets = JsonConvert.DeserializeObject<List<Attributes>>(e.Result);
        this.lbTweets.ItemsSource = tweets;
    }
    public class Attributes
    {
        public string STATE_NAME { get; set; }
    }
I can't deserialize the STATE_NAME attributes. What am I missing?
I keep getting this error
"Cannot deserialize JSON object into type 'System.Collections.Generic.List`1[WPJsonSample.MainPage+Attributes]'. Line 1, position 20."
Here is your class structure ( I used http://json2csharp.com/)
public class FieldAliases
{
    public string STATE_NAME { get; set; }
}
public class Field
{
    public string name { get; set; }
    public string type { get; set; }
    public string alias { get; set; }
    public int length { get; set; }
}
public class Attributes
{
    public string STATE_NAME { get; set; }
}
public class Feature
{
    public Attributes attributes { get; set; }
}
public class RootObject
{
    public string displayFieldName { get; set; }
    public FieldAliases fieldAliases { get; set; }
    public List<Field> fields { get; set; }
    public List<Feature> features { get; set; }
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With