【发布时间】:2017-09-16 14:15:39
【问题描述】:
我正在开发一个需要从本地 android 资产目录 访问 Json 数据的项目。我可以使用 Volley Library 从 assets 文件夹中读取 json 数据,但我想使用 Retrofit 做同样的事情。下面是我的 json 文件 - myfile.json 。
{
"formules": [
{
"formule": "Linear Motion",
"url": "<html><body>You scored <b>192</b> points. <img src=\"http://192.168.1.46/shanta_holdings/img/images/project-thumbs/Glasshouse-1.jpg\" alt=\"Smiley face\"/></body></html> ",
"des":"Here is a description"
},
{
"formule": "Constant Acceleration Motion",
"url": "<html><body>You scored <b>192</b> points. <img src=\"http://192.168.1.46/shanta_holdings/img/images/project-thumbs/Glasshouse-1.jpg\" alt=\"Smiley face\"/></body></html> ",
"des":"Here is a description"
},
{
"formule": "Projectile Motion",
"url": "<html><body>You scored <b>192</b> points. <img src=\"http://192.168.1.46/shanta_holdings/img/images/project-thumbs/Glasshouse-1.jpg\" alt=\"Smiley face\"/></body></html> ",
"des":"Here is a description"
},
{
"formule": "Force",
"url": "<html><body>You scored <b>192</b> points. <img src=\"http://192.168.1.46/shanta_holdings/img/images/project-thumbs/Glasshouse-1.jpg\" alt=\"Smiley face\"/></body></html> ",
"des":"Here is a description"
},
{
"formule": "Work, Power, Energy",
"url": "<html><body>You scored <b>192</b> points. <img src=\"http://192.168.1.46/shanta_holdings/img/images/project-thumbs/Glasshouse-1.jpg\" alt=\"Smiley face\"/></body></html> ",
"des":"Here is a description"
},
{
"formule": "Rotary Motion",
"url": "<html><body>You scored <b>192</b> points. <img src=\"http://192.168.1.46/shanta_holdings/img/images/project-thumbs/Glasshouse-1.jpg\" alt=\"Smiley face\"/></body></html> ",
"des":"Here is a description"
},
{
"formule": "Harmonic Motion",
"url": "<html><body>You scored <b>192</b> points. <img src=\"http://192.168.1.46/shanta_holdings/img/images/project-thumbs/Glasshouse-1.jpg\" alt=\"Smiley face\"/></body></html> ",
"des":"Here is a description"
},
{
"formule": "Gravity",
"url": "<html><body>You scored <b>192</b> points. <img src=\"http://192.168.1.46/shanta_holdings/img/images/project-thumbs/Glasshouse-1.jpg\" alt=\"Smiley face\"/></body></html> ",
"des":"Here is a description"
},
{
"formule": "Lateral and Longitudinal Waves",
"url": "<html><body>You scored <b>192</b> points. <img src=\"http://192.168.1.46/shanta_holdings/img/images/project-thumbs/Glasshouse-1.jpg\" alt=\"Smiley face\"/></body></html> ",
"des":"Here is a description"
},
{
"formule": "Sound Waves",
"url": "<html><body>You scored <b>192</b> points. <img src=\"http://192.168.1.46/shanta_holdings/img/images/project-thumbs/Glasshouse-1.jpg\" alt=\"Smiley face\"/></body></html> ",
"des":"Here is a description"
},
{
"formule": "Electrostatics",
"url": "<html><body>You scored <b>192</b> points. <img src=\"http://192.168.1.46/shanta_holdings/img/images/project-thumbs/Glasshouse-1.jpg\" alt=\"Smiley face\"/></body></html> ",
"des":"Here is a description"
},
{
"formule": "Direct Current",
"url": "<html><body>You scored <b>192</b> points. <img src=\"http://192.168.1.46/shanta_holdings/img/images/project-thumbs/Glasshouse-1.jpg\" alt=\"Smiley face\"/></body></html> ",
"des":"Here is a description"
},
{
"formule": "Magnetic Field",
"url": "https://www.google.com/",
"des":"Here is a description"
},
{
"formule": "Alternating Current",
"url": "https://www.google.com/",
"des":"Here is a description"
},
{
"formule": "Thermodynamics",
"url": "https://www.google.com/",
"des":"Here is a description"
},
{
"formule": "Hydrogen Atom",
"url": "https://www.google.com/",
"des":"Here is a description"
},
{
"formule": "Optics",
"url": "https://www.google.com/",
"des":"Here is a description"
},
{
"formule": "Modern Physics",
"url": "https://www.google.com/",
"des":"Here is a description"
},
{
"formule": "Hydrostatics",
"url": "https://www.google.com/",
"des":"Here is a description"
},
{
"formule": "Astronomy",
"url": "https://www.google.com/",
"des":"Here is a description"
}
]
}
我已经搜索了一周,但没有找到任何合适的改造解决方案。我可以使用 Retrofit 从服务器读取数据。有没有办法使用改造来实现要求。
【问题讨论】:
-
我认为 Volly 和 Retrofit 用于 rest API 不用于从资产文件夹转换 JSON,使用 GSON 进行解析。
-
我有一个问题:为什么? 为什么要在不应该使用 Volley 和 Retrofit 的地方使用它们?为什么不想直接加载文件?
标签: android json android-volley retrofit retrofit2