android api 17 之前如何获取屏幕,如何从wunderground API获取数据并将其显示在Android屏幕上?...

这将取决于数据的类型。 Concider是一个从JSON Feed中抽取地震数据位置的示例。

try {

JSONObject object = (JSONObject) new JSONTokener(JSONResponse)

.nextValue();

JSONArray earthquakes = object.getJSONArray("features");

for (int i = 0; i < earthquakes.length(); i++) {

JSONObject tmp = (JSONObject) earthquakes.get(i);

//Log.i("JSON: ",tmp.toString());

JSONObject geometry = tmp.getJSONObject("geometry");

JSONArray coords = geometry.getJSONArray("coordinates");

JSONObject properties = tmp.getJSONObject("properties");

//Log.i("Data", "Coords:"+coords.getString(0) + " "+ coords.getString(1)+"\n Place:"+properties.getString("place")+ " Mag:"+properties.getString("mag"));

if(coords.getString(0) != "" && coords.getString(1) != ""){

result.add(new EarthQuakeRec(

Float.parseFloat(coords.getString(1)),//Lat

Float.parseFloat(coords.getString(0)),//Long

Float.parseFloat(properties.getString("mag")),//Magnitude

properties.getString("place")

)

);

}

}

} catch (JSONException e) {

e.printStackTrace();

}

而且JSON结构看起来是这样的:

{

"id": "nc72241526",

"type": "Feature",

"geometry": {

"type": "Point",

"coordinates": [

-122.0102,

37.6053,

6

]

},

"properties": {

"detail": "http://earthquake.usgs.gov/earthquakes/feed/v1.0/detail/nc72241526.geojson",

"type": "earthquake",

"net": "nc",

"tsunami": null,

"sources": ",nc,",

"title": "M 3.0 - 1km NE of Union City, California",

"time": 1403371328500,

"updated": 1403374699020,

"mag": 3,

"types": ",dyfi,focal-mechanism,general-link,geoserve,nearby-cities,origin,phase-data,scitech-link,tectonic-summary,",

"place": "1km NE of Union City, California",

"status": "AUTOMATIC",

"ids": ",nc72241526,",

"alert": null,

"rms": 0.17,

"code": "72241526",

"url": "http://earthquake.usgs.gov/earthquakes/eventpage/nc72241526",

"magType": "Md",

"mmi": null,

"cdi": 3.8,

"tz": -420,

"felt": 319,

"nst": 75,

"dmin": 0.03593261,

"gap": 25.2,

"sig": 260

}

}

然后你就开始与JSONObject的类,然后深入到感兴趣的数据点。使用Log类可以帮助您在遍历数据结构时排除故障并衡量您的进度。在我的例子中,它被注释掉了。

对于XML,你可以尝试的东西的这个调:

try {

// Create the Pull Parser

XmlPullParserFactory factory = XmlPullParserFactory.newInstance();

XmlPullParser xpp = factory.newPullParser();

// Set the Parser's input to be the XML document in the HTTP Response

xpp.setInput(new InputStreamReader(response.getEntity()

.getContent()));

// Get the first Parser event and start iterating over the XML document

int eventType = xpp.getEventType();

while (eventType != XmlPullParser.END_DOCUMENT) {

if (eventType == XmlPullParser.START_TAG) {

startTag(xpp.getName());

} else if (eventType == XmlPullParser.END_TAG) {

endTag(xpp.getName());

} else if (eventType == XmlPullParser.TEXT) {

text(xpp.getText());

}

eventType = xpp.next();

}

return mResults;

} catch (XmlPullParserException e) {

e.printStackTrace();

}

这是很多在你扔的,但你并没有给太多的特异性。希望有所帮助。 ;)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值