开发者

How to use JSONDeserializer to deserialize this string?

I have string like follows:

    {"226167":"myshow","3193":"yourshow"}

How can I use JSONDeserializer to extract (226167,3193)开发者_Python百科 from the above string object?

I probably want to have a list (226167,3193,...) from the above string. I am using flexjason 1.9.2 and it doesn't have jsonObject class.


Use the jackson JSON library's ObjectMapper class to deserialize into a Map and then get the keySet():

Required Import:

import org.codehaus.jackson.map.ObjectMapper;

Example:

public void readValueAsMap() throws Exception
{
    String value = "{\"226167\":\"myshow\",\"3193\":\"yourshow\"}";
    ObjectMapper mapper = new ObjectMapper();
    Map<String,String> valueAsMap = mapper.readValue(value, Map.class);
    Collection<String> values = valueAsMap.keySet();
    assertTrue(values.contains("226167"));
    assertTrue(values.contains("3193"));
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜