This is the code. I am getting Diesel rate through API . And i have sample code, i Don't know how to implement this code in my C#.net Code Like in my Page load
public class cities
{
public string city { get; set; }
public string petrol { get; set; }
public string diesel { get; set; }
public string petrol_yesterday { get; set; }
public string state { get; set; }
public string date { get; set; }
}
and Deserialize your json result to your class
cities list = Newtonsoft.Json.JsonConvert.DeserializeObject<cities>(jsonInput);
public class cities
{
public string city { get; set; }
public string petrol { get; set; }
public string diesel { get; set; }
public string petrol_yesterday { get; set; }
public string state { get; set; }
public string date { get; set; }
}
dynamic jsonObject = Newtonsoft.Json.Linq.JObject.Parse(json);
string jsonToDeserializeStrongType = jsonObject["cities"].ToString();
List<cities> result = Newtonsoft.Json.JsonConvert.DeserializeObject<List<cities>>(jsonToDeserializeStrongType); ;
var singleRow = result.Find(x => x.city.Equals("Chennai"));// this line return as same as you want
Response.Write(singleRow.city + " " + singleRow.date + " " + singleRow.diesel);
And i try to eat individual data like chennai only you sent me
publicclass cities
{publicstring city {get;set;}publicstring petrol {get;set;}publicstring diesel {get;set;}publicstring petrol_yesterday {get;set;}publicstring state {get;set;}publicstring date {get;set;}}
Member
147 Points
239 Posts
json format to c#.Net Code
Jun 05, 2018 07:41 AM|vivekbuv|LINK
Dear Friends
This is the code. I am getting Diesel rate through API . And i have sample code, i Don't know how to implement this code in my C#.net Code Like in my Page load
I don't know what type of code this. Please tell me how to transfer this code to C#.net code format. I am new this
Star
8119 Points
2778 Posts
Re: json format to c#.Net Code
Jun 05, 2018 08:13 AM|vahid bakkhi|LINK
hi
you can use WebRequest below like:
Please MARK AS ANSWER if suggestion helps.
Member
147 Points
239 Posts
Re: json format to c#.Net Code
Jun 05, 2018 08:18 AM|vivekbuv|LINK
Thanks Vahid,
Thank you and i need one more, i am getting data like that
How can i separate each data... Thanks
Star
8119 Points
2778 Posts
Re: json format to c#.Net Code
Jun 05, 2018 08:25 AM|vahid bakkhi|LINK
you have create a class same as your json result
and Deserialize your json result to your class
Please MARK AS ANSWER if suggestion helps.
Star
8119 Points
2778 Posts
Re: json format to c#.Net Code
Jun 05, 2018 08:38 AM|vahid bakkhi|LINK
I created a sample for parse json result
and
Please MARK AS ANSWER if suggestion helps.
Member
147 Points
239 Posts
Re: json format to c#.Net Code
Jun 05, 2018 10:12 AM|vivekbuv|LINK
Thnaks for reply,
How can i get exact one data. Like i need one data
""city"": ""Chennai"", ""petrol"": ""80.80"", ""diesel"": ""72.72"", ""petrol_yesterday"": ""81.09"", ""diesel_yesterday"": ""72.97"", ""state"": ""Tamil Nadu"", ""date"": ""05-06-2018""
How can i get exact data??
Star
8119 Points
2778 Posts
Re: json format to c#.Net Code
Jun 05, 2018 10:23 AM|vahid bakkhi|LINK
please try below code :
Please MARK AS ANSWER if suggestion helps.
Member
147 Points
239 Posts
Re: json format to c#.Net Code
Jun 05, 2018 10:36 AM|vivekbuv|LINK
Thank you so much .... Its very useful
Member
147 Points
239 Posts
Re: json format to c#.Net Code
Jun 11, 2018 07:29 AM|vivekbuv|LINK
Dear Friend,
This Line not working
ERROR
{"Cannot perform runtime binding on a null reference"}
i am getting this error.
Star
8119 Points
2778 Posts
Re: json format to c#.Net Code
Jun 11, 2018 07:41 AM|vahid bakkhi|LINK
your json value is null, you must check it before
Please MARK AS ANSWER if suggestion helps.
Member
147 Points
239 Posts
Re: json format to c#.Net Code
Jun 11, 2018 07:49 AM|vivekbuv|LINK
Dear Friend,
Already you sent me set of code for my request but when i use i am getting error i put it full code.
And i try to eat individual data like chennai only you sent me
Here i am getting this error
string jsonToDeserializeStrongType = jsonObject["cities"].ToString();