android - 如何解析json对象内的json数组?
问题描述
我尝试在我的代码中设置这种类型的 json 响应我尝试在一个文本视图中设置问题并为其他文本视图设置答案
{
"subcategory": {
"id": 1,
"category_id": 1,
"name": "MLB - Major League Baseball",
"upload": null,
"total_points": [
{
"id": 1,
"user_id": 3,
"subcategory_id": 1,
"total": 10
}
],
"questions": [
{
"id": 1,
"subcategory_id": 1,
"question": "This is a test question.",
"link": "",
"banner_link": "",
"answers": [
{
"id": 1,
"question_id": 1,
"answer": "Answer 1",
"point": 10
},
{
"id": 2,
"question_id": 1,
"answer": "Answer 2",
"point": 20
},
{
"id": 3,
"question_id": 1,
"answer": "Answer 3",
"point": 30
},
{
"id": 4,
"question_id": 1,
"answer": "Answer 4",
"point": 40
}
],
}
如何在android中传递这种类型的json响应,例如一个文本视图中的问题显示和另一个文本视图中的答案显示?
解决方案
首先,您应该向您的应用程序文件添加依赖gradle
项,然后您将能够使用@Serialize
java 对象类中的注释来序列化您的 json 对象。之后,您可以将您的问题和答案放在适当的位置TextView
推荐阅读
- r - R中的替代特定条件Logit
- sequelize.js - 如何使用 sequelize 实现批量更新?
- r - 如何使用 pgmm 估计此回归?R
- tensorflow - 如何修复:'RuntimeError:会话图为空。在调用 run() 之前向图中添加操作。
- java - 使用带有身份验证标头的 AWS API 网关上传音频
- php - 管理员在 Laravel 中创建用户
- c++ - 我在这个程序中收到“退出,浮点异常”的错误,你能解释一下并给我新代码,为什么会这样?
- flutter - 使用 getX 颤振图像选择器
- tensorflow2.0 - graph_def.ParseFromString(f.read()) google.protobuf.message.DecodeError:解析消息时出错
- spring-security - 在同一个身份验证管理器中列出多个身份验证提供程序