TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Olumuyiwa Afolabi
NA
203
0
How to read Json file with asp.net c#
Jul 22 2019 5:13 AM
I want to display the JSON data in gridview. I have been able to pass some array to the gridview but I have not been able to pass this needed file
//JSON code please note that Properties > parameter > Precot values can be more than this based on api query
json url: https://power.larc.nasa.gov/cgi-bin/v1/DataAccess.py?&request=execute&identifier=SinglePoint¶meters=PRECTOT,RH2M,PS,T2M_RANGE,T2MDEW,T2M_MAX,T2M_MIN,WS10M_RANGE&startDate=20190715&endDate=20190721&userCommunity=AG&tempAverage=DAILY&outputList=JSON&lat=7.2146&lon=5.1641
{
"features": [
{
"geometry": {
"coordinates": [
5.16411,
7.21461,
292.62
],
"type": "Point"
},
"properties": {
"parameter": {
"PRECTOT": {
"20190715": 13.02,
"20190716": 11.49,
"20190717": 3.28,
"20190718": 6.42,
"20190719": 10.57,
"20190720": -99.0,
"20190721": -99.0
},
"PS": {
"20190715": 97.81,
"20190716": 97.95,
"20190717": 97.97,
"20190718": 97.87,
"20190719": 98.03,
"20190720": -99.0,
"20190721": -99.0
},
"RH2M": {
"20190715": 90.18,
"20190716": 91.44,
"20190717": 86.81,
"20190718": 91.07,
"20190719": 92.92,
"20190720": -999.0,
"20190721": -999.0
},
"T2MDEW": {
"20190715": 22.77,
"20190716": 22.24,
"20190717": 22.65,
"20190718": 22.75,
"20190719": 21.78,
"20190720": -99.0,
"20190721": -99.0
},
"T2M_MAX": {
"20190715": 27.75,
"20190716": 26.3,
"20190717": 29.42,
"20190718": 27.36,
"20190719": 25.07,
"20190720": -99.0,
"20190721": -99.0
},
"T2M_MIN": {
"20190715": 22.29,
"20190716": 21.79,
"20190717": 21.17,
"20190718": 22.33,
"20190719": 21.01,
"20190720": -99.0,
"20190721": -99.0
},
"T2M_RANGE": {
"20190715": 5.46,
"20190716": 4.51,
"20190717": 8.25,
"20190718": 5.03,
"20190719": 4.06,
"20190720": -999.0,
"20190721": -999.0
},
"WS10M_RANGE": {
"20190715": 1.66,
"20190716": 1.79,
"20190717": 0.68,
"20190718": 2.09,
"20190719": 3.16,
"20190720": -999.0,
"20190721": -999.0
}
}
},
"type": "Feature"
}
],
"header": {
"api_version": "1.1.0",
"endDate": "20190721",
"fillValue": "-99",
"startDate": "20190715",
"title": "NASA/POWER SRB/FLASHFlux/MERRA2/GEOS 5.12.4 (FP-IT) 0.5 x 0.5 Degree Daily Averaged Data"
},
"messages": [],
"outputs": {
"json": "https://power.larc.nasa.gov/downloads/POWER_SinglePoint_Daily_20190715_20190721_007d21N_005d16E_20d99a90.json"
},
"parameterInformation": {
"PRECTOT": {
"longname": "Precipitation",
"units": "mm day-1"
},
"PS": {
"longname": "Surface Pressure",
"units": "kPa"
},
"RH2M": {
"longname": "Relative Humidity at 2 Meters",
"units": "%"
},
"T2MDEW": {
"longname": "Dew/Frost Point at 2 Meters",
"units": "C"
},
"T2M_MAX": {
"longname": "Maximum Temperature at 2 Meters",
"units": "C"
},
"T2M_MIN": {
"longname": "Minimum Temperature at 2 Meters",
"units": "C"
},
"T2M_RANGE": {
"longname": "Temperature Range at 2 Meters",
"units": "C"
},
"WS10M_RANGE": {
"longname": "Wind Speed Range at 10 Meters",
"units": "m/s"
}
},
"time": [
[
"Main OPeNDAP Requests:",
1.346397876739502
],
[
"Total Script:",
11.816264152526855
]
],
"type": "FeatureCollection"
}
//// Generated class object from c#
public class Geometry
{
public List<double> coordinates { get; set; }
public string type { get; set; }
}
public class PRECTOT
{
public double __invalid_name__20190715 { get; set; }
public double __invalid_name__20190716 { get; set; }
public double __invalid_name__20190717 { get; set; }
public double __invalid_name__20190718 { get; set; }
public double __invalid_name__20190719 { get; set; }
public double __invalid_name__20190720 { get; set; }
public double __invalid_name__20190721 { get; set; }
}
public class PS
{
public double __invalid_name__20190715 { get; set; }
public double __invalid_name__20190716 { get; set; }
public double __invalid_name__20190717 { get; set; }
public double __invalid_name__20190718 { get; set; }
public double __invalid_name__20190719 { get; set; }
public double __invalid_name__20190720 { get; set; }
public double __invalid_name__20190721 { get; set; }
}
public class RH2M
{
public double __invalid_name__20190715 { get; set; }
public double __invalid_name__20190716 { get; set; }
public double __invalid_name__20190717 { get; set; }
public double __invalid_name__20190718 { get; set; }
public double __invalid_name__20190719 { get; set; }
public double __invalid_name__20190720 { get; set; }
public double __invalid_name__20190721 { get; set; }
}
public class T2MDEW
{
public double __invalid_name__20190715 { get; set; }
public double __invalid_name__20190716 { get; set; }
public double __invalid_name__20190717 { get; set; }
public double __invalid_name__20190718 { get; set; }
public double __invalid_name__20190719 { get; set; }
public double __invalid_name__20190720 { get; set; }
public double __invalid_name__20190721 { get; set; }
}
public class T2MMAX
{
public double __invalid_name__20190715 { get; set; }
public double __invalid_name__20190716 { get; set; }
public double __invalid_name__20190717 { get; set; }
public double __invalid_name__20190718 { get; set; }
public double __invalid_name__20190719 { get; set; }
public double __invalid_name__20190720 { get; set; }
public double __invalid_name__20190721 { get; set; }
}
public class T2MMIN
{
public double __invalid_name__20190715 { get; set; }
public double __invalid_name__20190716 { get; set; }
public double __invalid_name__20190717 { get; set; }
public double __invalid_name__20190718 { get; set; }
public double __invalid_name__20190719 { get; set; }
public double __invalid_name__20190720 { get; set; }
public double __invalid_name__20190721 { get; set; }
}
public class T2MRANGE
{
public double __invalid_name__20190715 { get; set; }
public double __invalid_name__20190716 { get; set; }
public double __invalid_name__20190717 { get; set; }
public double __invalid_name__20190718 { get; set; }
public double __invalid_name__20190719 { get; set; }
public double __invalid_name__20190720 { get; set; }
public double __invalid_name__20190721 { get; set; }
}
public class WS10MRANGE
{
public double __invalid_name__20190715 { get; set; }
public double __invalid_name__20190716 { get; set; }
public double __invalid_name__20190717 { get; set; }
public double __invalid_name__20190718 { get; set; }
public double __invalid_name__20190719 { get; set; }
public double __invalid_name__20190720 { get; set; }
public double __invalid_name__20190721 { get; set; }
}
public class Parameter
{
public PRECTOT PRECTOT { get; set; }
public PS PS { get; set; }
public RH2M RH2M { get; set; }
public T2MDEW T2MDEW { get; set; }
public T2MMAX T2M_MAX { get; set; }
public T2MMIN T2M_MIN { get; set; }
public T2MRANGE T2M_RANGE { get; set; }
public WS10MRANGE WS10M_RANGE { get; set; }
}
public class Properties
{
public Parameter parameter { get; set; }
}
public class Feature
{
public Geometry geometry { get; set; }
public Properties properties { get; set; }
public string type { get; set; }
}
public class Header
{
public string api_version { get; set; }
public string endDate { get; set; }
public string fillValue { get; set; }
public string startDate { get; set; }
public string title { get; set; }
}
public class Outputs
{
public string json { get; set; }
}
public class PRECTOT2
{
public string longname { get; set; }
public string units { get; set; }
}
public class PS2
{
public string longname { get; set; }
public string units { get; set; }
}
public class RH2M2
{
public string longname { get; set; }
public string units { get; set; }
}
public class T2MDEW2
{
public string longname { get; set; }
public string units { get; set; }
}
public class T2MMAX2
{
public string longname { get; set; }
public string units { get; set; }
}
public class T2MMIN2
{
public string longname { get; set; }
public string units { get; set; }
}
public class T2MRANGE2
{
public string longname { get; set; }
public string units { get; set; }
}
public class WS10MRANGE2
{
public string longname { get; set; }
public string units { get; set; }
}
public class ParameterInformation
{
public PRECTOT2 PRECTOT { get; set; }
public PS2 PS { get; set; }
public RH2M2 RH2M { get; set; }
public T2MDEW2 T2MDEW { get; set; }
public T2MMAX2 T2M_MAX { get; set; }
public T2MMIN2 T2M_MIN { get; set; }
public T2MRANGE2 T2M_RANGE { get; set; }
public WS10MRANGE2 WS10M_RANGE { get; set; }
}
public class RootObject
{
public List<Feature> features { get; set; }
public Header header { get; set; }
public List<object> messages { get; set; }
public Outputs outputs { get; set; }
public ParameterInformation parameterInformation { get; set; }
public List<List<object>> time { get; set; }
public string type { get; set; }
}
//Deserilizer used
RootObject rootObj = JsonConvert.DeserializeObject<RootObject>((json));
GridView1.DataSource = rootObj.PSArray;
GridView1.DataBind();
//Expected output
//For protect
Name Value
20190710 3.27
20190711 17.77
20190712 2.85
20190713 0.63
20190714 2.49
20190715 11.4
20190716 17.24
20190717 2.12
20190718 7.58
20190719 15.02
20190720 5.53
20190721 -99
20190722 -99
//For PS
Name Value
20190710 3.27
20190711 17.77
20190712 2.85
20190713 0.63
20190714 2.49
20190715 11.4
20190716 17.24
20190717 2.12
20190718 7.58
20190719 15.02
20190720 5.53
20190721 -99
20190722 -99
//For RH2M
Name Value
20190710 3.27
20190711 17.77
20190712 2.85
20190713 0.63
20190714 2.49
20190715 11.4
20190716 17.24
20190717 2.12
20190718 7.58
20190719 15.02
20190720 5.53
20190721 -99
20190722 -99
etc.
please note that the names and value could be more than this based on date selected from api
Thanks in advance: full source code will be much appreciated
Reply
Answers (
3
)
Unable to attach to the process
application state management object