Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is actually pretty easy. I will illustrate making the call to the REST service and parsing the JSON data into a class. Then I think you'll be able to do the string concatenation and display on your own.</p> <p>Start by adding a reference to the System.ServiceModel.Web assembly, which will give you access to the <a href="http://msdn.microsoft.com/en-us/library/system.runtime.serialization.json.datacontractjsonserializer%28v=VS.95%29.aspx" rel="nofollow">DataContractJsonSerializer</a> in the System.Runtime.Serialization.Json namespace.</p> <p>Next, create a class to represent the JSON. Use auto-implemented properties whose names match the JSON returned by the service:</p> <pre><code>public class ExchangeRate { public string lhs { get; set; } public string rhs { get; set; } public string error { get; set; } public string icc { get; set; } } </code></pre> <p>I'll assume you want to get the data when a button is clicked, so here's a small app with a button click handler.</p> <pre><code>using System; using System.Net; using System.Runtime.Serialization.Json; using System.Windows; using Microsoft.Phone.Controls; namespace WP7JsonClient { public partial class MainPage : PhoneApplicationPage { public MainPage() { InitializeComponent(); } private void button1_Click( object sender, RoutedEventArgs e ) { var client = new WebClient(); // Callback function written in-line as a lambda statement client.OpenReadCompleted += ( s, eargs ) =&gt; { var serializer = new DataContractJsonSerializer( typeof( ExchangeRate ) ); var exchangeRate = (ExchangeRate)serializer.ReadObject( eargs.Result ); // display exchange rate data here... }; var uri = new Uri( "http://www.google.com/ig/calculator?hl=en&amp;q=10USD=?DKK" ); client.OpenReadAsync( uri ); } } } </code></pre> <p>I've written the async callback method in-line as a lambda statement, but you could just as easily write that as a separate method. After the call to have the serializer read the object, the JSON data is now available as an instance of your JSON serialization class (ExchangeRate) so you can work with that object directly, perform data-binding with its properties, and so on.</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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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