首页 > 代码库 > (网络数据交互)Android解析Internet的Json资源文件

(网络数据交互)Android解析Internet的Json资源文件

常用的Internet数据解析格式和工具:

网页显示的json数据如下:

{"type":"FeatureCollection","metadata":{"generated":1480079277000,"url":"http://earthquake.usgs.gov/fdsnws/event/1/query?format=geojson&starttime=2016-11-24&endtime=2016-11-25&minmagnitude=4.5","title":"USGS Earthquakes","status":200,"api":"1.5.2","count":11},"features":[{"type":"Feature","properties":{"mag":4.5,"place":"139km SSW of Puerto El Triunfo, El Salvador","time":1480029756040,"updated":1480041472114,"tz":-360,"url":"http://earthquake.usgs.gov/earthquakes/eventpage/us10007c68","detail":"http://earthquake.usgs.gov/fdsnws/event/1/query?eventid=us10007c68&format=geojson","felt":2,"cdi":3.8,"mmi":null,"alert":null,"status":"reviewed","tsunami":0,"sig":312,"net":"us","code":"10007c68","ids":",us10007c68,","sources":",us,","types":",cap,dyfi,geoserve,origin,phase-data,","nst":null,"dmin":1.56,"rms":1.01,"gap":162,"magType":"mb","type":"earthquake","title":"M 4.5 - 139km SSW of Puerto El Triunfo, El Salvador"},"geometry":{"type":"Point","coordinates":[-89.0646,12.1253,10]},"id":"us10007c68"},
{"type":"Feature","properties":{"mag":4.5,"place":"74km W of Nikol‘skoye, Russia","time":1480028577300,"updated":1480030204040,"tz":660,"url":"http://earthquake.usgs.gov/earthquakes/eventpage/us10007c65","detail":"http://earthquake.usgs.gov/fdsnws/event/1/query?eventid=us10007c65&format=geojson","felt":null,"cdi":null,"mmi":null,"alert":null,"status":"reviewed","tsunami":0,"sig":312,"net":"us","code":"10007c65","ids":",us10007c65,","sources":",us,","types":",cap,geoserve,origin,phase-data,","nst":null,"dmin":4.185,"rms":0.68,"gap":153,"magType":"mb","type":"earthquake","title":"M 4.5 - 74km W of Nikol‘skoye, Russia"},"geometry":{"type":"Point","coordinates":[164.8447,55.0659,34.17]},"id":"us10007c65"},
{"type":"Feature","properties":{"mag":5.5,"place":"89km W of Nikol‘skoye, Russia","time":1480026661760,"updated":1480034180975,"tz":660,"url":"http://earthquake.usgs.gov/earthquakes/eventpage/us10007c5y","detail":"http://earthquake.usgs.gov/fdsnws/event/1/query?eventid=us10007c5y&format=geojson","felt":null,"cdi":null,"mmi":3.68,"alert":"green","status":"reviewed","tsunami":0,"sig":465,"net":"us","code":"10007c5y","ids":",us10007c5y,","sources":",us,","types":",cap,geoserve,losspager,origin,phase-data,shakemap,","nst":null,"dmin":4.128,"rms":1.19,"gap":57,"magType":"mb","type":"earthquake","title":"M 5.5 - 89km W of Nikol‘skoye, Russia"},"geometry":{"type":"Point","coordinates":[164.5815,55.2253,37.63]},"id":"us10007c5y"},
{"type":"Feature","properties":{"mag":5.4,"place":"80km SW of Yonakuni, Japan","time":1480024552160,"updated":1480065440447,"tz":480,"url":"http://earthquake.usgs.gov/earthquakes/eventpage/us10007c5s","detail":"http://earthquake.usgs.gov/fdsnws/event/1/query?eventid=us10007c5s&format=geojson","felt":21,"cdi":3.2,"mmi":null,"alert":null,"status":"reviewed","tsunami":0,"sig":455,"net":"us","code":"10007c5s","ids":",us10007c5s,","sources":",us,","types":",cap,dyfi,geoserve,origin,phase-data,","nst":null,"dmin":0.729,"rms":1.08,"gap":51,"magType":"mb","type":"earthquake","title":"M 5.4 - 80km SW of Yonakuni, Japan"},"geometry":{"type":"Point","coordinates":[122.4034,23.9916,10]},"id":"us10007c5s"},
{"type":"Feature","properties":{"mag":7,"place":"149km SSW of Puerto El Triunfo, El Salvador","time":1480013028830,"updated":1480054542419,"tz":-360,"url":"http://earthquake.usgs.gov/earthquakes/eventpage/us10007c4w","detail":"http://earthquake.usgs.gov/fdsnws/event/1/query?eventid=us10007c4w&format=geojson","felt":211,"cdi":5.4,"mmi":4.55,"alert":"green","status":"reviewed","tsunami":1,"sig":868,"net":"us","code":"10007c4w","ids":",at00oh5td3,pt16329050,us10007c4w,","sources":",at,pt,us,","types":",cap,dyfi,geoserve,impact-link,losspager,moment-tensor,origin,phase-data,shakemap,","nst":null,"dmin":1.759,"rms":1.14,"gap":20,"magType":"mww","type":"earthquake","title":"M 7.0 - 149km SSW of Puerto El Triunfo, El Salvador"},"geometry":{"type":"Point","coordinates":[-88.8355,11.9597,10.34]},"id":"us10007c4w"},
{"type":"Feature","properties":{"mag":4.6,"place":"35km NNW of Chakwal, Pakistan","time":1479996997260,"updated":1480068498740,"tz":300,"url":"http://earthquake.usgs.gov/earthquakes/eventpage/us10007c3e","detail":"http://earthquake.usgs.gov/fdsnws/event/1/query?eventid=us10007c3e&format=geojson","felt":14,"cdi":4.7,"mmi":null,"alert":null,"status":"reviewed","tsunami":0,"sig":332,"net":"us","code":"10007c3e","ids":",us10007c3e,","sources":",us,","types":",cap,dyfi,geoserve,origin,phase-data,","nst":null,"dmin":0.58,"rms":1.38,"gap":248,"magType":"mb","type":"earthquake","title":"M 4.6 - 35km NNW of Chakwal, Pakistan"},"geometry":{"type":"Point","coordinates":[72.7709,33.2447,35.02]},"id":"us10007c3e"},
{"type":"Feature","properties":{"mag":5,"place":"166km S of L‘Esperance Rock, New Zealand","time":1479993351100,"updated":1479995808040,"tz":-720,"url":"http://earthquake.usgs.gov/earthquakes/eventpage/us10007c33","detail":"http://earthquake.usgs.gov/fdsnws/event/1/query?eventid=us10007c33&format=geojson","felt":null,"cdi":null,"mmi":null,"alert":null,"status":"reviewed","tsunami":0,"sig":385,"net":"us","code":"10007c33","ids":",us10007c33,","sources":",us,","types":",cap,geoserve,origin,phase-data,","nst":null,"dmin":3.703,"rms":0.99,"gap":81,"magType":"mb","type":"earthquake","title":"M 5.0 - 166km S of L‘Esperance Rock, New Zealand"},"geometry":{"type":"Point","coordinates":[-178.6018,-32.9146,10]},"id":"us10007c33"},
{"type":"Feature","properties":{"mag":4.9,"place":"Northern Mid-Atlantic Ridge","time":1479983824980,"updated":1479986627040,"tz":-180,"url":"http://earthquake.usgs.gov/earthquakes/eventpage/us10007c2d","detail":"http://earthquake.usgs.gov/fdsnws/event/1/query?eventid=us10007c2d&format=geojson","felt":null,"cdi":null,"mmi":null,"alert":null,"status":"reviewed","tsunami":0,"sig":369,"net":"us","code":"10007c2d","ids":",us10007c2d,","sources":",us,","types":",cap,geoserve,origin,phase-data,","nst":null,"dmin":12.643,"rms":0.89,"gap":153,"magType":"mb","type":"earthquake","title":"M 4.9 - Northern Mid-Atlantic Ridge"},"geometry":{"type":"Point","coordinates":[-40.9692,31.5236,10]},"id":"us10007c2d"},
{"type":"Feature","properties":{"mag":4.6,"place":"Galapagos Islands, Ecuador region","time":1479979712670,"updated":1479981459040,"tz":-360,"url":"http://earthquake.usgs.gov/earthquakes/eventpage/us10007c21","detail":"http://earthquake.usgs.gov/fdsnws/event/1/query?eventid=us10007c21&format=geojson","felt":null,"cdi":null,"mmi":null,"alert":null,"status":"reviewed","tsunami":0,"sig":326,"net":"us","code":"10007c21","ids":",us10007c21,","sources":",us,","types":",cap,geoserve,origin,phase-data,","nst":null,"dmin":4.033,"rms":0.84,"gap":169,"magType":"mb","type":"earthquake","title":"M 4.6 - Galapagos Islands, Ecuador region"},"geometry":{"type":"Point","coordinates":[-93.0873,2.2479,10]},"id":"us10007c21"},
{"type":"Feature","properties":{"mag":4.8,"place":"34km SE of Namie, Japan","time":1479962890050,"updated":1479965791976,"tz":540,"url":"http://earthquake.usgs.gov/earthquakes/eventpage/us10007c0i","detail":"http://earthquake.usgs.gov/fdsnws/event/1/query?eventid=us10007c0i&format=geojson","felt":1,"cdi":2.7,"mmi":null,"alert":null,"status":"reviewed","tsunami":0,"sig":355,"net":"us","code":"10007c0i","ids":",us10007c0i,","sources":",us,","types":",cap,dyfi,geoserve,origin,phase-data,","nst":null,"dmin":0.725,"rms":0.89,"gap":134,"magType":"mb","type":"earthquake","title":"M 4.8 - 34km SE of Namie, Japan"},"geometry":{"type":"Point","coordinates":[141.243,37.2384,24.84]},"id":"us10007c0i"},
{"type":"Feature","properties":{"mag":5.2,"place":"210km SW of Hachijo-jima, Japan","time":1479947710110,"updated":1479948789040,"tz":540,"url":"http://earthquake.usgs.gov/earthquakes/eventpage/us10007by5","detail":"http://earthquake.usgs.gov/fdsnws/event/1/query?eventid=us10007by5&format=geojson","felt":null,"cdi":null,"mmi":null,"alert":null,"status":"reviewed","tsunami":0,"sig":416,"net":"us","code":"10007by5","ids":",us10007by5,","sources":",us,","types":",cap,geoserve,origin,phase-data,","nst":null,"dmin":1.919,"rms":0.76,"gap":72,"magType":"mb","type":"earthquake","title":"M 5.2 - 210km SW of Hachijo-jima, Japan"},"geometry":{"type":"Point","coordinates":[138.202,31.7602,350.12]},"id":"us10007by5"}],"bbox":[-178.6018,-32.9146,10,164.8447,55.2253,350.12]}

上述文件需要通过一种规范进行解析,如下使用json格式解析工具,生成的数据文件:

{
    "type": "FeatureCollection",
    "metadata": {
        "generated": 1480079277000,
        "url": "http://earthquake.usgs.gov/fdsnws/event/1/query?format=geojson&starttime=2016-11-24&endtime=2016-11-25&minmagnitude=4.5",
        "title": "USGS Earthquakes",
        "status": 200,
        "api": "1.5.2",
        "count": 11
    },
    "features": [
        {
            "type": "Feature",
            "properties": {
                "mag": 4.5,
                "place": "139km SSW of Puerto El Triunfo, El Salvador",
                "time": 1480029756040,
                "updated": 1480041472114,
                "tz": -360,
                "url": "http://earthquake.usgs.gov/earthquakes/eventpage/us10007c68",
                "detail": "http://earthquake.usgs.gov/fdsnws/event/1/query?eventid=us10007c68&format=geojson",
                "felt": 2,
                "cdi": 3.8,
                "mmi": null,
                "alert": null,
                "status": "reviewed",
                "tsunami": 0,
                "sig": 312,
                "net": "us",
                "code": "10007c68",
                "ids": ",us10007c68,",
                "sources": ",us,",
                "types": ",cap,dyfi,geoserve,origin,phase-data,",
                "nst": null,
                "dmin": 1.56,
                "rms": 1.01,
                "gap": 162,
                "magType": "mb",
                "type": "earthquake",
                "title": "M 4.5 - 139km SSW of Puerto El Triunfo, El Salvador"
            },
            "geometry": {
                "type": "Point",
                "coordinates": [
                    -89.0646,
                    12.1253,
                    10
                ]
            },
            "id": "us10007c68"
        },
        {
            "type": "Feature",
            "properties": {
                "mag": 4.5,
                "place": "74km W of Nikol‘skoye, Russia",
                "time": 1480028577300,
                "updated": 1480030204040,
                "tz": 660,
                "url": "http://earthquake.usgs.gov/earthquakes/eventpage/us10007c65",
                "detail": "http://earthquake.usgs.gov/fdsnws/event/1/query?eventid=us10007c65&format=geojson",
                "felt": null,
                "cdi": null,
                "mmi": null,
                "alert": null,
                "status": "reviewed",
                "tsunami": 0,
                "sig": 312,
                "net": "us",
                "code": "10007c65",
                "ids": ",us10007c65,",
                "sources": ",us,",
                "types": ",cap,geoserve,origin,phase-data,",
                "nst": null,
                "dmin": 4.185,
                "rms": 0.68,
                "gap": 153,
                "magType": "mb",
                "type": "earthquake",
                "title": "M 4.5 - 74km W of Nikol‘skoye, Russia"
            },
            "geometry": {
                "type": "Point",
                "coordinates": [
                    164.8447,
                    55.0659,
                    34.17
                ]
            },
            "id": "us10007c65"
        },
        {
            "type": "Feature",
            "properties": {
                "mag": 5.5,
                "place": "89km W of Nikol‘skoye, Russia",
                "time": 1480026661760,
                "updated": 1480034180975,
                "tz": 660,
                "url": "http://earthquake.usgs.gov/earthquakes/eventpage/us10007c5y",
                "detail": "http://earthquake.usgs.gov/fdsnws/event/1/query?eventid=us10007c5y&format=geojson",
                "felt": null,
                "cdi": null,
                "mmi": 3.68,
                "alert": "green",
                "status": "reviewed",
                "tsunami": 0,
                "sig": 465,
                "net": "us",
                "code": "10007c5y",
                "ids": ",us10007c5y,",
                "sources": ",us,",
                "types": ",cap,geoserve,losspager,origin,phase-data,shakemap,",
                "nst": null,
                "dmin": 4.128,
                "rms": 1.19,
                "gap": 57,
                "magType": "mb",
                "type": "earthquake",
                "title": "M 5.5 - 89km W of Nikol‘skoye, Russia"
            },
            "geometry": {
                "type": "Point",
                "coordinates": [
                    164.5815,
                    55.2253,
                    37.63
                ]
            },
            "id": "us10007c5y"
        },
        {
            "type": "Feature",
            "properties": {
                "mag": 5.4,
                "place": "80km SW of Yonakuni, Japan",
                "time": 1480024552160,
                "updated": 1480065440447,
                "tz": 480,
                "url": "http://earthquake.usgs.gov/earthquakes/eventpage/us10007c5s",
                "detail": "http://earthquake.usgs.gov/fdsnws/event/1/query?eventid=us10007c5s&format=geojson",
                "felt": 21,
                "cdi": 3.2,
                "mmi": null,
                "alert": null,
                "status": "reviewed",
                "tsunami": 0,
                "sig": 455,
                "net": "us",
                "code": "10007c5s",
                "ids": ",us10007c5s,",
                "sources": ",us,",
                "types": ",cap,dyfi,geoserve,origin,phase-data,",
                "nst": null,
                "dmin": 0.729,
                "rms": 1.08,
                "gap": 51,
                "magType": "mb",
                "type": "earthquake",
                "title": "M 5.4 - 80km SW of Yonakuni, Japan"
            },
            "geometry": {
                "type": "Point",
                "coordinates": [
                    122.4034,
                    23.9916,
                    10
                ]
            },
            "id": "us10007c5s"
        },
        {
            "type": "Feature",
            "properties": {
                "mag": 7,
                "place": "149km SSW of Puerto El Triunfo, El Salvador",
                "time": 1480013028830,
                "updated": 1480054542419,
                "tz": -360,
                "url": "http://earthquake.usgs.gov/earthquakes/eventpage/us10007c4w",
                "detail": "http://earthquake.usgs.gov/fdsnws/event/1/query?eventid=us10007c4w&format=geojson",
                "felt": 211,
                "cdi": 5.4,
                "mmi": 4.55,
                "alert": "green",
                "status": "reviewed",
                "tsunami": 1,
                "sig": 868,
                "net": "us",
                "code": "10007c4w",
                "ids": ",at00oh5td3,pt16329050,us10007c4w,",
                "sources": ",at,pt,us,",
                "types": ",cap,dyfi,geoserve,impact-link,losspager,moment-tensor,origin,phase-data,shakemap,",
                "nst": null,
                "dmin": 1.759,
                "rms": 1.14,
                "gap": 20,
                "magType": "mww",
                "type": "earthquake",
                "title": "M 7.0 - 149km SSW of Puerto El Triunfo, El Salvador"
            },
            "geometry": {
                "type": "Point",
                "coordinates": [
                    -88.8355,
                    11.9597,
                    10.34
                ]
            },
            "id": "us10007c4w"
        },
        {
            "type": "Feature",
            "properties": {
                "mag": 4.6,
                "place": "35km NNW of Chakwal, Pakistan",
                "time": 1479996997260,
                "updated": 1480068498740,
                "tz": 300,
                "url": "http://earthquake.usgs.gov/earthquakes/eventpage/us10007c3e",
                "detail": "http://earthquake.usgs.gov/fdsnws/event/1/query?eventid=us10007c3e&format=geojson",
                "felt": 14,
                "cdi": 4.7,
                "mmi": null,
                "alert": null,
                "status": "reviewed",
                "tsunami": 0,
                "sig": 332,
                "net": "us",
                "code": "10007c3e",
                "ids": ",us10007c3e,",
                "sources": ",us,",
                "types": ",cap,dyfi,geoserve,origin,phase-data,",
                "nst": null,
                "dmin": 0.58,
                "rms": 1.38,
                "gap": 248,
                "magType": "mb",
                "type": "earthquake",
                "title": "M 4.6 - 35km NNW of Chakwal, Pakistan"
            },
            "geometry": {
                "type": "Point",
                "coordinates": [
                    72.7709,
                    33.2447,
                    35.02
                ]
            },
            "id": "us10007c3e"
        },
        {
            "type": "Feature",
            "properties": {
                "mag": 5,
                "place": "166km S of L‘Esperance Rock, New Zealand",
                "time": 1479993351100,
                "updated": 1479995808040,
                "tz": -720,
                "url": "http://earthquake.usgs.gov/earthquakes/eventpage/us10007c33",
                "detail": "http://earthquake.usgs.gov/fdsnws/event/1/query?eventid=us10007c33&format=geojson",
                "felt": null,
                "cdi": null,
                "mmi": null,
                "alert": null,
                "status": "reviewed",
                "tsunami": 0,
                "sig": 385,
                "net": "us",
                "code": "10007c33",
                "ids": ",us10007c33,",
                "sources": ",us,",
                "types": ",cap,geoserve,origin,phase-data,",
                "nst": null,
                "dmin": 3.703,
                "rms": 0.99,
                "gap": 81,
                "magType": "mb",
                "type": "earthquake",
                "title": "M 5.0 - 166km S of L‘Esperance Rock, New Zealand"
            },
            "geometry": {
                "type": "Point",
                "coordinates": [
                    -178.6018,
                    -32.9146,
                    10
                ]
            },
            "id": "us10007c33"
        },
        {
            "type": "Feature",
            "properties": {
                "mag": 4.9,
                "place": "Northern Mid-Atlantic Ridge",
                "time": 1479983824980,
                "updated": 1479986627040,
                "tz": -180,
                "url": "http://earthquake.usgs.gov/earthquakes/eventpage/us10007c2d",
                "detail": "http://earthquake.usgs.gov/fdsnws/event/1/query?eventid=us10007c2d&format=geojson",
                "felt": null,
                "cdi": null,
                "mmi": null,
                "alert": null,
                "status": "reviewed",
                "tsunami": 0,
                "sig": 369,
                "net": "us",
                "code": "10007c2d",
                "ids": ",us10007c2d,",
                "sources": ",us,",
                "types": ",cap,geoserve,origin,phase-data,",
                "nst": null,
                "dmin": 12.643,
                "rms": 0.89,
                "gap": 153,
                "magType": "mb",
                "type": "earthquake",
                "title": "M 4.9 - Northern Mid-Atlantic Ridge"
            },
            "geometry": {
                "type": "Point",
                "coordinates": [
                    -40.9692,
                    31.5236,
                    10
                ]
            },
            "id": "us10007c2d"
        },
        {
            "type": "Feature",
            "properties": {
                "mag": 4.6,
                "place": "Galapagos Islands, Ecuador region",
                "time": 1479979712670,
                "updated": 1479981459040,
                "tz": -360,
                "url": "http://earthquake.usgs.gov/earthquakes/eventpage/us10007c21",
                "detail": "http://earthquake.usgs.gov/fdsnws/event/1/query?eventid=us10007c21&format=geojson",
                "felt": null,
                "cdi": null,
                "mmi": null,
                "alert": null,
                "status": "reviewed",
                "tsunami": 0,
                "sig": 326,
                "net": "us",
                "code": "10007c21",
                "ids": ",us10007c21,",
                "sources": ",us,",
                "types": ",cap,geoserve,origin,phase-data,",
                "nst": null,
                "dmin": 4.033,
                "rms": 0.84,
                "gap": 169,
                "magType": "mb",
                "type": "earthquake",
                "title": "M 4.6 - Galapagos Islands, Ecuador region"
            },
            "geometry": {
                "type": "Point",
                "coordinates": [
                    -93.0873,
                    2.2479,
                    10
                ]
            },
            "id": "us10007c21"
        },
        {
            "type": "Feature",
            "properties": {
                "mag": 4.8,
                "place": "34km SE of Namie, Japan",
                "time": 1479962890050,
                "updated": 1479965791976,
                "tz": 540,
                "url": "http://earthquake.usgs.gov/earthquakes/eventpage/us10007c0i",
                "detail": "http://earthquake.usgs.gov/fdsnws/event/1/query?eventid=us10007c0i&format=geojson",
                "felt": 1,
                "cdi": 2.7,
                "mmi": null,
                "alert": null,
                "status": "reviewed",
                "tsunami": 0,
                "sig": 355,
                "net": "us",
                "code": "10007c0i",
                "ids": ",us10007c0i,",
                "sources": ",us,",
                "types": ",cap,dyfi,geoserve,origin,phase-data,",
                "nst": null,
                "dmin": 0.725,
                "rms": 0.89,
                "gap": 134,
                "magType": "mb",
                "type": "earthquake",
                "title": "M 4.8 - 34km SE of Namie, Japan"
            },
            "geometry": {
                "type": "Point",
                "coordinates": [
                    141.243,
                    37.2384,
                    24.84
                ]
            },
            "id": "us10007c0i"
        },
        {
            "type": "Feature",
            "properties": {
                "mag": 5.2,
                "place": "210km SW of Hachijo-jima, Japan",
                "time": 1479947710110,
                "updated": 1479948789040,
                "tz": 540,
                "url": "http://earthquake.usgs.gov/earthquakes/eventpage/us10007by5",
                "detail": "http://earthquake.usgs.gov/fdsnws/event/1/query?eventid=us10007by5&format=geojson",
                "felt": null,
                "cdi": null,
                "mmi": null,
                "alert": null,
                "status": "reviewed",
                "tsunami": 0,
                "sig": 416,
                "net": "us",
                "code": "10007by5",
                "ids": ",us10007by5,",
                "sources": ",us,",
                "types": ",cap,geoserve,origin,phase-data,",
                "nst": null,
                "dmin": 1.919,
                "rms": 0.76,
                "gap": 72,
                "magType": "mb",
                "type": "earthquake",
                "title": "M 5.2 - 210km SW of Hachijo-jima, Japan"
            },
            "geometry": {
                "type": "Point",
                "coordinates": [
                    138.202,
                    31.7602,
                    350.12
                ]
            },
            "id": "us10007by5"
        }
    ],
    "bbox": [
        -178.6018,
        -32.9146,
        10,
        164.8447,
        55.2253,
        350.12
    ]
}

根据上述生成的规范Json文件,编写对应的Java Bean文件。

(网络数据交互)Android解析Internet的Json资源文件