0

我正在使用杰克逊解析器。应该在模型类中创建什么类型的字段来使用 Object Mapper 解析以下字段。

directions":
{
 "1":"Heat oil in a nonstick skillet coated with cooking spray over medium heat. Add red bell pepper and garlic; cook, uncovered, 30 minutes, stirring occasionally. Set aside, and cool slightly.",
 "2":"Place pepper mixture in a blender; add chopped basil and next 3 ingredients. Process until smooth, stopping once to scrape down sides.",
 "3":"Cook pasta according to package directions, omitting salt and fat.",
 "4":"To serve, top pasta with pepper sauce. Garnish with basil sprigs, if desired."
}

我已经创建了该字段

private HashMap<String,String> directions;

但是在解析时显示异常

 com.fasterxml.jackson.databind.JsonMappingException: Can not instantiate value of type [map type; class java.util.HashMap, [simple type, class java.lang.String] -> [simple type, class java.lang.String]] from String value;
 no single-String constructor/factory method (through reference chain: com.project.android.vo.ModelClass["directions"])
4

0 回答 0