从Json Feed中提取JSON数据

时间:2014-09-07 13:56:27

标签: android json jsonobject

我正在尝试使用json feed提取数据。但由于没有JSONObject,我得到NullPointerexception。

我正在尝试提取以下数据。

{"postcode":"HA0 4TL","geo": {"lat":51.55135528090932,"lng":-0.29906534560684617,"easting":518029.0,"northing":184978.0,"geohash":"http://geohash.org/gcpv30whrm0s"},"administrative":{"council":{"title":"Brent","uri":"http://statistics.data.gov.uk/id/statistical-geography/E09000005","code":"E09000005"},"ward":{"title":"Wembley Central","uri":"http://statistics.data.gov.uk/id/statistical-geography/E05000104","code":"E05000104"},"constituency":{"title":"Brent North","uri":"http://statistics.data.gov.uk/id/statistical-geography/E14000592","code":"E14000592"}}}

我可以按照以下方式创建JSONObject。

String in;
JSONObject reader = new JSONObject(in);

但我怎样才能获得邮编?

以下代码返回NullPointerException。

JSONObject postCode  = reader.getJSONObject("postcode");

1 个答案:

答案 0 :(得分:2)

你应该使用

String postCode = reader.getString("postcode");