I am trying to read json data that is coming from a api, and I just want to read objects from this data..
string id_url = "http://abc/some_id";
WebRequest requst = WebRequest.Create(id_url);
requst.Method = "GET";
requst.Headers["Authorization"] = "Basic " + Convert.ToBase64String(Encoding.Default.GetBytes("user:password"));
HttpWebResponse response = requst.GetResponse() as HttpWebResponse;
var encod = ASCIIEncoding.ASCII;
using (var readchat = new System.IO.StreamReader(response.GetResponseStream(), encod))
{
string chatresult = readchat.ReadToEnd();
var json = JObject.Parse(chatresult);
}
and I am getting json
as:
{
"comment": null,
"triggered_response": true,
"rating": null,
"visitor": {
"phone": "",
"name": "abc"
},
"history": [
{
"name": "Visitor 7949",
"department_name": null,
"type": "chat.memberjoin",
"department_id": null
},
{
"name": "fdef",
"sender_type": "Trigger",
"msg": "Welcome back! How may I help you today?",
"type": "chat.msg"
},
{
"name": "use",
"sender_type": "Trigger",
"msg": "good morning",
"type": "chat.msg"
}
]
}
I have to read only "msg" tag data from json
using C#. I have tried this:
string data = json["history"].ToString();
by using above am getting the data from "history" tag but how will am able to get text from history[array].msg as we do using javascript ajax.