c.jack c.jack - 1 month ago 5
JSON Question

How to display object variable value in label

I have a method which has object return type in a class library, I am using javascript Deserializer and returning the object data. And created the DLL of this class and calling this class in another project. I am getting the data in that class but confuse how to display the object type data in label controls.

This is the class library method:

public class HttpRequestResponse
private WebRequest request;
public object Fetchresult()
request = WebRequest.Create("URL");
request.Method = "GET";
request.ContentType = "application/json; charset=utf-8";
WebResponse response = request.GetResponse(); Console.WriteLine(((HttpWebResponse)response).StatusDescription);
dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
string responseFromServer = reader.ReadToEnd();
JavaScriptSerializer js = new JavaScriptSerializer();
object obj = js.Deserialize<dynamic>(responseFromServer);
return obj;


This is the calling class:

HttpRequestResponse cls = new HttpRequestResponse();
object obj= cls.Fetchresult();
Label3.Text = obj["name"];

I am getting the value in
but how to display this value in label control.


Here is the solution

dynamic obj = cls.Fetchresult(i);