json字符串的解析

public static void main(String[] args) throws Exception {
        // 菜單json字符串
        String menustr = "{\"url\":\"this_is_url\",\"requestMethod\":\"POST\",\"requestDate\":{\"button\":[{\"type\":\"click\",\"name\":\"今日歌曲\","
                + "\"key\":\"V1001_TODAY_MUSIC\"},{\"name\":\"菜單\","
                + "\"sub_button\":[{\"type\":\"view\",\"name\":\"搜索\",\"url\":\"http://www.soso.com/\"},"
                + "{\"type\":\"view\",\"name\":\"視頻\",\"url\":\"http://v.qq.com/\"},"
                + "{\"type\":\"click\",\"name\":\"贊一下我們\",\"key\":\"V1001_GOOD\"}]}]}}";
        System.out.println("menustr:" + menustr);
        JSONObject jsonObject = new JSONObject(menustr);
        String requestUrl = jsonObject.getString("url");
        String requestMethod = jsonObject.getString("requestMethod");
        String requestDate = jsonObject.getString("requestDate");

        System.out.println("requestUrl:" + requestUrl);
        System.out.println("requestMethod:" + requestMethod);
        System.out.println("requestDate:" + requestDate);
        }

運行結果:

menustr:{"url":"this_is_url","requestMethod":"POST","requestDate":{"button":[{"type":"click","name":"今日歌曲","key":"V1001_TODAY_MUSIC"},{"name":"菜單","sub_button":[{"type":"view","name":"搜索","url":"http://www.soso.com/"},{"type":"view","name":"視頻","url":"http://v.qq.com/"},{"type":"click","name":"贊一下我們","key":"V1001_GOOD"}]}]}}
requestUrl:this_is_url
requestMethod:POST
requestDate:{"button":[{"name":"今日歌曲","type":"click","key":"V1001_TODAY_MUSIC"},{"name":"菜單","sub_button":[{"name":"搜索","type":"view","url":"http://www.soso.com/"},{"name":"視頻","type":"view","url":"http://v.qq.com/"},{"name":"贊一下我們","type":"click","key":"V1001_GOOD"}]}]}
 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章