Note that there are some explanatory texts on larger screens.

plurals
  1. POConversion of JSON object to C# object
    primarykey
    data
    text
    <p>Please consider the following code: </p> <pre><code>using System; using System.ComponentModel; using System.Collections.Generic; using System.Diagnostics; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; using System.Collections.ObjectModel; using System.IO; using System.Xml.Linq; using System.Runtime.Serialization.Json; using System.Net; namespace wideeye4 { public class MainViewModel : INotifyPropertyChanged { public MainViewModel() { this.Items = new ObservableCollection&lt;ItemViewModel&gt;(); } /// &lt;summary&gt; /// A collection for ItemViewModel objects. /// &lt;/summary&gt; public ObservableCollection&lt;ItemViewModel&gt; Items { get; private set; } private string _sampleProperty = "Sample Runtime Property Value"; /// &lt;summary&gt; /// Sample ViewModel property; this property is used in the view to display its value using a Binding /// &lt;/summary&gt; /// &lt;returns&gt;&lt;/returns&gt; public string SampleProperty { get { return _sampleProperty; } set { if (value != _sampleProperty) { _sampleProperty = value; NotifyPropertyChanged("SampleProperty"); } } } public bool IsDataLoaded { get; private set; } /// &lt;summary&gt; /// Creates and adds a few ItemViewModel objects into the Items collection. /// &lt;/summary&gt; public void LoadData() { try { WebClient webclient = new WebClient(); Uri uri = new Uri(&lt;http://192.168.100.100:3000/listings.json&gt;); webclient.OpenReadCompleted += new OpenReadCompletedEventHandler(webclient_openreadcompleted); webclient.OpenReadAsync(uri); } catch (Exception ex) { MessageBox.Show(ex.Message); } } void webclient_openreadcompleted(object sender, OpenReadCompletedEventArgs e) { DataContractJsonSerializer serializer = null; try { serializer = new DataContractJsonSerializer(typeof(ObservableCollection&lt;wideeye&gt;)); e.Result.Position = 0; var sr = new StreamReader(e.Result); var json = sr.ReadToEnd(); ObservableCollection&lt;wideeye&gt; wideeyes = serializer.ReadObject(e.Result) as ObservableCollection&lt;wideeye&gt;; foreach (wideeye wd in wideeyes) { string varlisting_id = string.Empty; string varlisting_image_file_name = string.Empty; if (wd.listing != null) { string varcategory = wd.listing.category; string varcity = wd.listing.city; } if (wd.listing_images != null) { varlisting_id = wd.listing_images.listing_id; varlisting_image_file_name = wd.listing_images.listing_image_file_name; } Items.Add(new ItemViewModel() { LineOne = wd.listing.category.ToString(), LineTwo = wd.listing.city.ToString(), LineThree = string.Format("http://wideeye.hopto.org:3000/system/listing_images/{0}/medium/{1}", varlisting_id, varlisting_image_file_name) }); } this.IsDataLoaded = true; } catch (Exception ex) { MessageBox.Show(ex.Message); } } public event PropertyChangedEventHandler PropertyChanged; private void NotifyPropertyChanged(String propertyName) { PropertyChangedEventHandler handler = PropertyChanged; if (null != handler) { handler(this, new PropertyChangedEventArgs(propertyName)); } } } } { [DataContract] public class wideeye { [DataMember] public listing listing { get; set; } [DataMember] public listing_images listing_images { get; set; } [DataMember] public bids bids { get; set; } [DataMember] public messages messages { get; set; } } [DataContract] public class listing { public string category { get; set; } public string city { get; set; } public string country { get; set; } public string created_at { get; set; } public string current_publish_date { get; set; } public string details { get; set; } public string id { get; set; } public string industry { get; set; } public string list_exp_date { get; set; } public string list_price { get; set; } public string list_start_date { get; set; } public string make { get; set; } public string model { get; set; } public string open_bid { get; set; } public string state { get; set; } public string status { get; set; } public string title { get; set; } public string updated_at { get; set; } public string year { get; set; } } [DataContract] public class listing_images { public string created_at { get; set; } public string id { get; set; } public string listing_id { get; set; } public string listing_image_content_type { get; set; } public string listing_image_file_name { get; set; } public string listing_image_file_size { get; set; } public string listing_image_updated_at { get; set; } public string updated_at { get; set; } } [DataContract] public class bids { public string bid_exp_date { get; set; } public string bid_price { get; set; } public string bid_status { get; set; } public string created_at { get; set; } public string event_type { get; set; } public string id { get; set; } public string listing_id { get; set; } public string msg_association_id { get; set; } public string msg_text { get; set; } public string msg_type { get; set; } public string updated_at { get; set; } public string user_id { get; set; } } [DataContract] public class messages { public string bid_exp_date { get; set; } public string bid_price { get; set; } public string bid_status { get; set; } public string created_at { get; set; } public string event_type { get; set; } public string id { get; set; } public string listing_id { get; set; } public string msg_association_id { get; set; } public string msg_text { get; set; } public string msg_type { get; set; } public string updated_at { get; set; } public string user_id { get; set; } } } </code></pre> <hr> <p>In webclient_openreadcompleted the event (<em><code>e.result</code></em>) is returning <code>MemoryStream</code>, so for that it is giving exception. I am facing a lot of problems as my JSON object is very large. I am using databoundWP7 model for this.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload