Jarray Get element values

Source: Internet
Author: User

#region Get JSON Getaqi
protected String Getaqi ()
{
string url = "http://www.pm25.in/api/querys/pm2_5.json?city= wuxi &token=5j1znbvasnsf5xqynqyq";
string r = String. Empty;
HttpWebRequest webRequest = (HttpWebRequest) webrequest.create (URL. ToString ());
HttpWebResponse WebResponse = (HttpWebResponse) webrequest.getresponse ();
//Return data flow from Internet resources
Stream webstream = WebResponse.GetResponseStream ();
//Read data stream
StreamReader webstreamreader = new StreamReader (Webstream, System.Text.Encoding.UTF8);
//Read Data
r = webstreamreader.readtoend ();
webstreamreader.close ();
webstream.close ();
webresponse.close ();

return R;


}
#endregion

For example:   Get the value of PM2.5 somewhere in Wuxi

[{"AQI": 0, "area": "Wuxi", "Pm2_5": 0, "pm2_5_24h": 0, "position_name": "Cao Zhang", "primary_pollutant": null, "quality": null, " Station_code ":" 1190A "," Time_point ":" 2015-05-26t12:00:00z "},{" AQI ":" Area ":" Wuxi "," Pm2_5 ":" pm2_5_24h ": 33," Position_name ":" Lacquer Pond "," primary_pollutant ":" Particulate matter (PM10) "," Quality ":" Liang "," Station_code ":" 1191A "," Time_point ":" 2015-05-26t12:00:00z "},{" AQI ":", "area": "Wuxi", "Pm2_5":, "pm2_5_24h": "Position_name": "East Pavilion", "primary_pollutant ":" Particulate matter (PM10) "," Quality ":" Good "," Station_code ":" 1192A "," Time_point ":" 2015-05-26t12:00:00z "},{" AQI ":," area ":" Wuxi ", "Pm2_5": "pm2_5_24h": "Position_name": "Wang Zhuang", "primary_pollutant": "Particulate matter (PM10)", "Quality": "Liang", "Station_code": " 1193A "," Time_point ":" 2015-05-26t12:00:00z "},{" AQI ": +," area ":" Wuxi "," pm2_5 ": +," pm2_5_24h ":," Position_name ":" Yan Qiao "," primary_pollutant ":" Particulate matter (PM10) "," Quality ":" Good "," Station_code ":" 1195A "," Time_point ":" 2015-05-26t12:00:00z "}, {"AQI": "Area": "Wuxi", "Pm2_5": "pm2_5_24h": "Position_name": "Snow Wave", "primary_pollutant": "Particulate matter (PM10)", "quality" : "Liang", "Station_code": "1188A "," Time_point ":" 2015-05-26t12:00:00z "},{" AQI ": +," area ":" Wuxi "," Pm2_5 ":," pm2_5_24h ": $," position_name ":" Huang Xiang " , "primary_pollutant": "Particulate matter (PM10)", "Quality": "Good", "Station_code": "1189A", "Time_point": "2015-05-26t12:00:00z"},{" AQI ":", "area": "Wuxi", "Pm2_5": "pm2_5_24h": "Position_name": "Rong Xiang", "primary_pollutant": "Particulate matter (PM10)", "Quality": " Good "," Station_code ":" 1194A "," Time_point ":" 2015-05-26t12:00:00z "},{" AQI ":," area ":" Wuxi "," pm2_5 ": +," pm2_5_24h ": 42 , "Position_name": null, "primary_pollutant": "Particulate matter (PM10)", "Quality": "Benign", "station_code": null, "Time_point": " 2015-05-26t12:00:00z "}]

Get a value in Jarray as follows:

Jarray Jo = (jarray) jsonconvert.deserializeobject (Getaqi ());

String AQI = jo[1]["AQI"]. ToString ();
String quality = jo[1]["quality"]. ToString ();

Results: aqi= "67"; Quality= "Liang";

Jarray Get element values

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.