将JSON映射到列表<map << string,object =“”>&gt;

时间:2017-06-22 11:42:47

标签: java json jackson

我有一个格式为

的json
[{
    "id" : "a01",
    "name" : "random1",
    "val" : "random2"

},
{
    "id" : "a03",
    "name" : "random3",
    "val" : "random4"
}]

我需要转换成地图列表。那么我怎么能得到相同的? 即使我能够将其转换为字符串列表,使每个字符串的格式为

{
    "id" : "a01",
    "name" : "random1",
    "val" : "random2"

}

我有一种将其转换为地图的方法。那么,如何提取这样的字符串列表?

3 个答案:

答案 0 :(得分:14)

您需要将eventRender: function(event, element, view){ element = $(element); if(event.holiday){ var date = moment(event.date).format("YYYY-MM-DD"); $(view.el[0]).find(".fc-day[data-date="+date+"]").html("<span>" + event.title + "</span>").addClass("holiday"); return false; } else { element.find('.fc-time').hide(); element.css("min-height", "30px").css("border-width", "0px").css("margin-bottom", "2px"); var text; var operator; element.addClass("course"+ event.id).addClass("event"+ event.id); if(event.quantity == 1){ operator = " Termin"; } else if (event.quantity > 1){ operator = " Termine"; } if(event.backgroundColor == "#fa3e54"){ text ='<form method="POST" action="/register/'+event.title +'"> <div class="coursename">'+event.title +'</div>' + '<div class="course-date">Kurs nicht mehr buchbar</div></form>'; } else { var register = '<div class="anmelden"><input type="hidden" name="token" value="'+event.id + ',' + event.date + ',' + event.time + ',' + event.quantity + '' + operator+'"><input type="submit" class="btn-u pull-right" value="Anmelden"></div></form>'; text ='<form method="POST" action="/register/'+event.title +'"> <div class="coursename">'+event.title +'</div>' + '<div class="course-date">Termine: '+ event.date + '</div>' + '<div class="course-time">Uhrzeit: '+ event.time + '</div>' + '<div class="coursequantity">Kursdauer: ' + event.quantity + ' ' + operator + '</div>' + register; element.find(".fc-content").append('<form method="POST" action="/register/'+event.title +'">'+register+'</form>'); } } 传递给具有所需结果类型的TypeReference

readValue

答案 1 :(得分:1)

使用指定类型的gson转换为地图列表:

Gson gson = new Gson();
Type resultType = new TypeToken<List<Map<String, Object>>>(){}.getType();
List<Map<String, Object>> result = gson.fromJson(json, resultType);

答案 2 :(得分:1)

私有列表> map_string;

Json,您需要通过:-

{
"map_formula" : [ 
        {
            "A+" : "if(price<400),\"40000\",0",
            "B" : "",
            "c" : "",
            "d" : "",
            "e" : ""
        }, 
        {
            "poor" : "value for poor",
            "good" : "300",
            "average" : "300",
            "excellent" : "300"
        }
    ]
}