1. 首页 > 数码

model.json文件怎么解析? json文件解析

model.json文件怎么解析?json文件解析

json数据如何解析

code.google/p/s60-json-library/

怎么解析json数据

<!DOCTYPE HTML>

<html>

<head>

<title>Page Title</title>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<script>

var data = {

    "HeWeather data service 3.0": [{

        "aqi": {

            "city": {

                "qlty": "优",

                "co": "1",

                "so2": "6",

                "aqi": "49",

                "no2": "45",

                "o3": "26",

                "pm10": "48",

                "pm25": "26"

            }

        },

        "daily_forecast": [{

            "pop": "0",

            "cond": {

                "code_n": "101",

                "code_d": "100",

                "txt_n": "多云",

                "txt_d": "晴"

            },

            "pcpn": "0",

            "tmp": {

                "max": "16",

                "min": "3"

            },

            "pres": "1031",

            "astro": {

                "ss": "17:14",

                "sr": "06:41"

            },

            "date": "2015-10-31",

            "hum": "19",

            "vis": "10",

            "wind": {

                "sc": "微风",

                "deg": "229",

                "spd": "0",

                "dir": "无持续风向"

            }

        }],

        "basic": {

            "id": "CN101010100",

            "city": "北京",

            "lat": "39.904000",

            "lon": "116.391000",

            "update": {

                "utc": "2015-10-31 03:49",

                "loc": "2015-10-31 11:49"

            },

            "cnty": "中国"

        }

    }]

};

var yugi = function(key,data) {

var optcd = Object.prototype.toString.call(data);

    if ( optcd == "[object Object]") {

        for (var k in data) {

            var dk = data[k];

            console.log(k+": " +dk);

              yugi(k,dk);

        }

    } else if (optcd == "[object Array]") {

        for (var i = 0; i < data.length; i++) {

            var di = data[i];

            console.log(i+": " +di);

              yugi(i,di);

        }

    } 

}

yugi(null,data);

</script>

</head>

<body>

</body>

</html>

求助,JSON解析完成后怎么转成Model

大部分情况使用json的格式来传递参数,但是使用起来就不太方便了,因此需要将json转换成对应的model,然后对model进行操作就很便利了。json转model的方法也有很多,推荐一个就是,jackson,方法是这样的。

public static T obj2Obj(Object fromValue, Class toValueType){

ObjectMapper mapper = new ObjectMapper();

mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

T t = mapper.convertValue(fromValue, toValueType);

return t;

}

json数据中有json数组 怎么解析

实例:

import net.sf.json.JSONArray;

public class TestJson

{

public static void main(String []args)

{

String json = "[{\"a\":\"111\",\"b\":\"222\",\"c\":\"333\"},{\"a\":\"1000\",\"b\":\"2000\",\"c\":\"000\"},{\"a\":\"999\",\"b\":\"300\",\"c\":\"700\"}]";

JSONArray jsonArr = JSONArray.fromObject(json);

String a[] = new String[jsonArr.size()];

String b[] = new String[jsonArr.size()];

String c[] = new String[jsonArr.size()];

for (int i = 0; i < jsonArr.size(); i++) {

a[i] = jsonArr.getJSONObject(i).getString("a");

b[i] = jsonArr.getJSONObject(i).getString("b");

c[i] = jsonArr.getJSONObject(i).getString("c");

}

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

System.out.print(a[i]+" ");

System.out.print(b[i]+" ");

System.out.print(c[i]);

System.out.println();

}

}

}