douliao8402
2018-03-07 15:46
浏览 482

如何在android中存储json数据以便离线

My application get JSON data from server. If I use my own json api , data is loaded only in internet connection. But if I use this api (https://pixabay.com/api/?key=5303976-fd6581ad4ac165d1b75cc15b3&q=kitten&image_type=photo&pretty=true), data is displayed also in offline, once application got internet connection.

The same code, one json url is loaded also after the loss of internet connectivity, another one's data doesn't display after internet disconnection. How to store data in android cache from server-side as this URL (https://pixabay.com/api/?key=5303976-fd6581ad4ac165d1b75cc15b3&q=kitten&image_type=photo&pretty=true).

My api (api1.php)

<?php 
    require("includes/connect.php");
header('Content-Type: application/json');

    $query="SELECT * FROM implink";
$result = $con->query('SELECT id,heading,content FROM implink');
$rows = $result->fetchAll(PDO::FETCH_ASSOC);
header('Content-Type: application/json;charset=utf-8');
echo json_encode(['info' => $rows],
        JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK);
?> 

图片转代码服务由CSDN问答提供 功能建议

我的应用程序从服务器获取JSON数据。 如果我使用我自己的json api ,则数据仅在互联网连接中加载。 但是如果我使用这个api( https: 应用程序上网后//pixabay.com/api/?key=5303976-fd6581ad4ac165d1b75cc15b3&q=kitten&image_type=photo&pretty=true ),数据也会在离线状态下显示 连接。

相同的代码,在失去互联网连接后也会加载一个json url,互联网断开连接后不显示另一个数据。 如何从服务器端将数据存储在android缓存中作为此URL( https://pixabay.com/api/?key=5303976-fd6581ad4ac165d1b75cc15b3&q=kitten&image_type=photo&pretty=true )。

我的api(api1.php)

 &lt;?php 
 require(“include /”  connect.php“); 
header('Content-Type:application / json'); 
 
 $ query =”SELECT * FROM implink“; 
 $ result = $ con&gt; query('SELECT id, 标题,内容FROM implink'); 
 $ rows = $ result-&gt; fetchAll(PDO :: FETCH_ASSOC); 
header('Content-Type:application / json; charset = utf-8'); 
echo json_encode(  ['info'=&gt; $ rows],
 JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK); 
?&gt;  
   
 
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题