2016-12-03 89 views
0

我有这样的JSON格式:解析此JSON格式

["[email protected][id=636,rapidViewId=69,state=CLOSED,name=ABC-1,startDate=2016-07-18T08:22:00.000-04:00,endDate=2016-07-29T04:15:00.000-04:00,completeDate=2016-08-09T10:34:24.009-04:00,sequence=636]", "[email protected][id=656,rapidViewId=69,state=ACTIVE,name=ABC-2,startDate=2016-08-09T10:42:41.342-04:00,endDate=2016-08-19T06:35:00.000-04:00,completeDate=<null>,sequence=656]"] 

我试图分析此使用GSON解析,但得到这个Expected BEGIN_OBJECT but was STRING at line 1 column 3 path $[0]

的Java代码和用于分析一个Spring bean是如下:

Type sprintBeanType = new TypeToken<List<SprintBean>>() {}.getType(); 
List<SprintBean> sprintBeanList = gson.fromJson(json, sprintBeanType); 

public class SprintBean{ 
    @Expose 
    private String sprint; 

    public String getSprint() { 
     return sprint; 
    } 

    public void setSprint(String sprint) { 
     this.sprint = sprint; 
    } 

} 

在解析这个JSON任何帮助,高度赞赏。

回答

0

你的JSON数据看起来它只是一个字符串列表,所以可以通过更换型通用和列表变种类型List<String>解析成一个List<String>

Type sprintStringType = new TypeToken<List<String>>() {}.getType(); 
List<String> sprintStringList = gson.fromJson(json, sprintStringType); 

然而,只有分析的基本JSON数据转换为字符串,“内部”数据将不会被解析。另外,你不可能使用GSON解析每个字符串,因为它不是有效的JSON数据。