deserialize json response to c# -


i not able deserialize following response : json

json {   "disclaimer": "exchange rates/",   "license": "data sourced various providers",   "timestamp": 1435813262,   "base": "usd",   "rates": {     "aed": 3.672973,     "afn": 60.150001,     "all": 126.7792,     "amd": 472.46,     "ang": 1.78875,     "aoa": 121.253666,     "ars": 9.095239,     "aud": 1.307011,     "awg": 1.793333,     "azn": 1.04955, } } 

controller :

[httppost] public actionresult index(test1 values) {      string appid = values.apikey;     httpwebrequest request = (httpwebrequest)webrequest.create("https://openexchangerates.org//api/latest.json?app_id=5db2fa81c8174a839756eb4d5a4a5e05");      request.method = "post";      using (streamwriter streamwriter = new streamwriter(request.getrequeststream(), asciiencoding.ascii))     {         streamwriter.write(appid1);         streamwriter.close();     }      string responsetext = string.empty;      if (request.headers.count > 0)     {          using (streamreader sr = new streamreader(request.getresponse().getresponsestream()))         {             responsetext = sr.readtoend();          }     }      var myobject = jsonconvert.deserializeobject(responsetext); } 

follow here : http://www.newtonsoft.com/json/help/html/deserializeobject.htm

do not forget declare class deserialized object. should contains fields json object has or of them.

i dont know if code works except deserializing process there code example below make understand meant:

class myclass {     public string disclaimer { get; set; }     public string license { get; set; }     public string timestamp { get; set; }     ... }  [httppost] public actionresult index(test1 values) {     ...     var myobject = jsonconvert.deserializeobject<myclass>(responsetext);     ... } 

Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -