Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Dynamics 365 general forum

DataContractSerializer For Dictionary

(0) ShareShare
ReportReport
Posted on by

I'm using DataContractJsonSerializer to get data from this API

https://api.exchangeratesapi.io/latest?base=USD

        void GetCurrencyRates(string BaseCurrency, double TotalPrice)

        {
            WebRequest request = WebRequest.Create("api.exchangeratesapi.io/latest");
            request.Method = "GET";
            WebResponse response = request.GetResponse();
            StreamReader sr = new StreamReader(response.GetResponseStream());
          
            using (MemoryStream DeSerializememoryStream = new MemoryStream())
            {
                DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(RootObject));

                StreamWriter writer = new StreamWriter(DeSerializememoryStream);
                string str = sr.ReadToEnd();
                writer.Write(str);
                writer.Flush();

                DeSerializememoryStream.Position = 0;
                RootObject SerializedObject = (RootObject)serializer.ReadObject(DeSerializememoryStream);
            }
        }

    [DataContract]
    public class RootObject
    {
        [DataMember(Name="base")]
        public string Base { get; set; }

        [DataMember(Name = "rates")]
        Dictionary<string, decimal> rates = new Dictionary<string, decimal>();
        
        [DataMember]
        public string date { get; set; }
    }


I'm able to get Data for Base and date but it is not pouplating rates Dictionary.

Please help.

  • RE: DataContractSerializer For Dictionary

    Please someone help

  • RE: DataContractSerializer For Dictionary

    I tried changing to

     List<KeyValuePair<string, string>> rates = new List<KeyValuePair<string, string>>();

    But still its not populating list

  • Kokulan Profile Picture
    Kokulan 18,052 on at

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,407 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans