Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

json data to array \ combo box

Posted on 2014-03-20
3
Medium Priority
?
777 Views
Last Modified: 2014-04-21
Hi Experts

I have some data that is pulled form a json query whichis called using an API from

https://openexchangerates.org/

"base": "USD",
 "rates": {
 "AED": 3.672989,
 "AFN": 57.200075,
 "ALL": 103.9367,
 "AMD": 407.992003,
 "ANG": 1.78894,
 "AOA": 97.430751,
 "ARS": 6.074665,
   
What i need is to be able select the given exchage rate from this list.

The full file has been attached, when extracting please put the file extension of .json at the end as was unable to upload with the extension still present do to EE rules.

I would be grateful if someone could tell me \ show me how i would accomplish this

many thanks

Simon
2013-11-21-file.zip
0
Comment
Question by:SimonPrice33
3 Comments
 
LVL 5

Expert Comment

by:jayakrishnabh
ID: 39942152
If you have the json data in any variable say 'ratesData'
Then access the rates as ratesData.rates.ZWL, ratesData.rates.AED, so on..

If you just have the file that has data, then assign it to a javascript variable as follows and access same way as above
var ratesData = {
            "disclaimer": "Exchange rates are provided for informational purposes only, and do not constitute financial advice of any kind. Although every attempt is made to ensure quality, NO guarantees are given whatsoever of accuracy, validity, availability, or fitness for any purpose - please use at your own risk. All usage is subject to your acceptance of the Terms and Conditions of Service, available at: https://openexchangerates.org/terms/",
            "license": "Data sourced from various providers with public-facing APIs; copyright may apply; resale is prohibited; no warranties given of any kind. All usage is subject to your acceptance of the License Agreement available at: https://openexchangerates.org/license/",
            "timestamp": 1385074800,
            "base": "USD",
            "rates": {
                "AED": 3.673051,
                "AFN": 57.3777,
                "ALL": 104.010999,
                "AMD": 408.432,
                "ANG": 1.78898,
                "AOA": 97.339476
}
};
0
 
LVL 20

Accepted Solution

by:
Daniel Van Der Werken earned 2000 total points
ID: 39942247
If you're looking for C# code and want to have the rates as an object you can select from out of a Dictionary. Here is the code. You will need to include System.Web.Extensions.dll

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Web.Script.Serialization;


namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {

private string jsonData = "{\"disclaimer\": \"Exchange rates are provided for informational purposes only, and do not constitute financial advice of any kind. Although every attempt is made to ensure quality, NO guarantees are given whatsoever of accuracy, validity, availability, or fitness for any purpose - please use at your own risk. All usage is subject to your acceptance of the Terms and Conditions of Service, available at: https://openexchangerates.org/terms/\",\"license\": \"Data sourced from various providers with public-facing APIs; copyright may apply; resale is prohibited; no warranties given of any kind. All usage is subject to your acceptance of the License Agreement available at: https://openexchangerates.org/license/\",\"timestamp\": 1385074800,\"base\": \"USD\",\"rates\": {\"AED\": 3.673051,\"AFN\": 57.3777,\"ALL\": 104.010999,\"AMD\": 408.432,\"ANG\": 1.78898,\"AOA\": 97.339476,\"ARS\": 6.05437,\"AUD\": 1.083098,\"AWG\": 1.78985,\"AZN\": 0.7842,\"BAM\": 1.450701,\"BBD\": 2,\"BDT\": 77.63584,\"BGN\": 1.451343,\"BHD\": 0.377012, \"BIF\": 1546.048433, \"BMD\": 1, \"BND\": 1.24814, \"BOB\": 6.90817, \"BRL\": 2.299399, \"BSD\": 1, \"BTC\": 0.00151391, \"BTN\": 62.787963, \"BWP\": 8.608688, \"BYR\": 9312.866667, \"BZD\": 1.99348, \"CAD\": 1.050811, \"CDF\": 926.433, \"CHF\": 0.91297, \"CLF\": 0.02246, \"CLP\": 521.9952, \"CNY\": 6.106574, \"COP\": 1926.33, \"CRC\": 498.587002, \"CUP\": 22.687419, \"CVE\": 81.78835, \"CZK\": 20.20724, \"DJF\": 177.344299, \"DKK\": 5.530372, \"DOP\": 42.53314, \"DZD\": 80.17803, \"EEK\": 11.701175, \"EGP\": 6.888601, \"ERN\": 15.002825, \"ETB\": 19.04046, \"EUR\": 0.741812, \"FJD\": 1.859013, \"FKP\": 0.617411, \"GBP\": 0.617411, \"GEL\": 1.6765, \"GHS\": 2.265631, \"GIP\": 0.617411, \"GMD\": 37.56986, \"GNF\": 6985, \"GTQ\": 7.91939, \"GYD\": 203.534998, \"HKD\": 7.752253, \"HNL\": 20.51968, \"HRK\": 5.670824, \"HTG\": 41.29926, \"HUF\": 220.733399, \"IDR\": 11682.166667, \"ILS\": 3.557579, \"INR\": 62.82237, \"IQD\": 1164.55335, \"IRR\": 24788.0013, \"ISK\": 122.046, \"JEP\": 0.617411, \"JMD\": 103.367001, \"JOD\": 0.708596, \"JPY\": 100.9382, \"KES\": 86.24561, \"KGS\": 48.7473, \"KHR\": 4006.1685, \"KMF\": 365.505739, \"KPW\": 900, \"KRW\": 1060.645016, \"KWD\": 0.283194, \"KYD\": 0.826373, \"KZT\": 152.906999, \"LAK\": 7962.428333, \"LBP\": 1507.24, \"LKR\": 131.099801, \"LRD\": 80.619868, \"LSL\": 10.133688, \"LTL\": 2.560181, \"LVL\": 0.521319, \"LYD\": 1.250681, \"MAD\": 8.307457, \"MDL\": 13.03434, \"MGA\": 2258.1, \"MKD\": 45.69423, \"MMK\": 975.04302, \"MNT\": 1710.666667, \"MOP\": 7.98269, \"MRO\": 295.1773, \"MTL\": 0.683738, \"MUR\": 30.51185, \"MVR\": 15.39669, \"MWK\": 403.83, \"MXN\": 13.02513, \"MYR\": 3.200664, \"MZN\": 29.92565, \"NAD\": 10.13075, \"NGN\": 158.954799, \"NIO\": 24.98624, \"NOK\": 6.092771, \"NPR\": 100.509001, \"NZD\": 1.217725, \"OMR\": 0.384993, \"PAB\": 1, \"PEN\": 2.80315, \"PGK\": 2.59555, \"PHP\": 43.73444, \"PKR\": 107.631499, \"PLN\": 3.109229, \"PYG\": 4427.389941, \"QAR\": 3.640789, \"RON\": 3.299638, \"RSD\": 84.589999, \"RUB\": 32.96826, \"RWF\": 670.92802, \"SAR\": 3.750558, \"SBD\": 7.18894, \"SCR\": 12.02347, \"SDG\": 4.429543, \"SEK\": 6.63114, \"SGD\": 1.248789, \"SHP\": 0.617411, \"SLL\": 4310.166833, \"SOS\": 1222.347233, \"SRD\": 3.283333, \"STD\": 18267.434, \"SVC\": 8.74706, \"SYP\": 140.119874, \"SZL\": 10.13569, \"THB\": 31.79718, \"TJS\": 4.77185, \"TMT\": 2.852167, \"TND\": 1.675864, \"TOP\": 1.818723, \"TRY\": 2.015451, \"TTD\": 6.40133, \"TWD\": 29.56181, \"TZS\": 1605.833333, \"UAH\": 8.20819, \"UGX\": 2521.976667, \"USD\": 1, \"UYU\": 20.98968, \"UZS\": 2159.552627, \"VEF\": 6.29131, \"VND\": 21097.8, \"VUV\": 94.705, \"WST\": 2.313154, \"XAF\": 486.74417, \"XAG\": 0.05012116, \"XAU\": 0.00080632, \"XCD\": 2.70152, \"XDR\": 0.653951, \"XOF\": 486.696001, \"XPF\": 88.94657, \"YER\": 215.071499, \"ZAR\": 10.13273, \"ZMK\": 5253.075255, \"ZMW\": 5.519867, \"ZWL\": 322.355006}}";

        public Form1()
        {
            InitializeComponent();
            Dictionary<string,object> o = (Dictionary<string,object>)Deserialize(jsonData);
            Dictionary<string, dynamic> dict = (Dictionary<string, dynamic>)o["rates"];
            var aud_value = dict["AUD"];
        }

        private static object Deserialize(string jsonString)
        {
            var jss = new JavaScriptSerializer();
            var obj = jss.Deserialize<Dictionary<string, dynamic>>(jsonString);
            return obj;
        }
    }
}

Open in new window


reference:
http://procbits.com/2011/04/21/quick-json-serializationdeserialization-in-c
0
 

Author Closing Comment

by:SimonPrice33
ID: 40013064
thank you
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question