如何正确地将Json解析为MP Android Chart?

时间:2019-05-27 17:11:04

标签: java android retrofit retrofit2 mpandroidchart

尝试获取此Json字符串以将其正确解析为MP Android Chart以创建一个漂亮的PieChart

[{"userId":"1","moodBefore":"Anxious","count(moodBefore)":"2"},      {"userId":"1","moodBefore":"Stressed","count(moodBefore)":"7"},{"userId":"1","moodBefore":"Upset","count(moodBefore)":"4"}]

我希望饼图显示心情名称(即“焦虑”)和每种心情的总数。

我的JAVA代码:

public class MoodLogList {
@SerializedName("count")
private int count;

@SerializedName("moodBefore")
private String moodBefore;

public String getMoodBefore() {
    return moodBefore;
}

public int getCount() {
    return count;
}
}

还有RETROFIT CALL片段

  Call<List<MoodLogList>> call = RetrofitClient.getInstance().getApi().moodLog(userId);
    call.enqueue(new Callback<List<MoodLogList>>() {
        @Override
        public void onResponse(Call<List<MoodLogList>> call, Response<List<MoodLogList>> response) {

            List<PieEntry> pieEntries = new ArrayList<>();

            for (MoodLogList moodLogList : response.body()) {

                pieEntries.add(new PieEntry(moodLogList.getMoodBefore(),   moodLogList.getCount()));

            }

当前pieChart的中间仅显示一个白色圆圈,没有任何数据。

0 个答案:

没有答案