您的位置:首页 > 移动开发 > Objective-C

使用jackson的ObjectMapper json转object

2017-06-21 17:54 453 查看
json 转 List<User>

CollectionType collectionType = MAPPER.getTypeFactory().constructCollectionType(ArrayList.class, GroupUser.class);
//the sieze of the list is dependon the str json length although the json content is not the POJO type maybe
ArrayList<GroupUser> groupUsers = MAPPER.readValue(res, collectionType);

json 转 数组

ArrayType arrayType = MAPPER.getTypeFactory().constructArrayType(User.class);
User[] users = MAPPER.readValue(expected, arrayType);


json 转 boject

User user = MAPPER.readValue(expected, User.class);


Object 转json

String test = MAPPER.writeValueAsString(users);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐