我需要从一个网址https://bter.com/api/1/ticker/btc_cny中读取数据
数据时json格式的,类似如下
{"result":"true","last":77.9,"high":78.95,"low":75.04,"avg":76.61,"sell":77.9,"buy":77.8,"vol_ltc":6000.8096,"vol_cny":459746.35}
数据每10秒更新,但是数据不一定会变,我怎么判断数据是否有刷新?
因为读取数据我需要存储起来,变化的数据才会存起来,不变的数据就不会存储起来。
如果每次读取的数据很多的话类似:
{"result":"true","data":[{"date":"1398348450","price":3088,"amount":0.8039,"tid":"7180798","type":"sell"},{"date":"1398348517","price":3085,"amount":0.8253,"tid":"7180825","type":"sell"},{"date":"1398348533","price":3084.19,"amount":0.0309,"tid":"7180828","type":"sell"},{"date":"1398348538","price":3084.19,"amount":0.039,"tid":"7180831","type":"sell"},{"date":"1398348603","price":3086.17,"amount":0.0176,"tid":"7180841","type":"sell"},{"date":"1398348697","price":3088,"amount":0.1631,"tid":"7180863","type":"buy"},{"date":"1398348702","price":3085.4,"amount":0.0601,"tid":"7180868","type":"sell"},{"date":"1398348707","price":3085.4,"amount":0.0697,"tid":"7180871","type":"sell"},{"date":"1398348712","price":3085.4,"amount":0.0526,"tid":"7180873","type":"sell"},{"date":"1398348807","price":3085.41,"amount":0.6088,"tid":"7180911","type":"sell"},{"date":"1398348818","price":3085.41,"amount":0.002,"tid":"7180913","type":"sell"},{"date":"1398348829","price":3088,"amount":0.0063,"tid":"7180916","type":"buy"},{"date":"1398348839","price":3088.1,"amount":0.0501,"tid":"7180923","type":"buy"},{"date":"1398348930","price":3086.41,"amount":0.1079,"tid":"7180943","type":"sell"},{"date":"1398348962","price":3089.2,"amount":0.0185,"tid":"7180948","type":"sell"},{"date":"1398348972","price":3090,"amount":0.031,"tid":"7180951","type":"buy"},{"date":"1398348983","price":3090,"amount":0.051,"tid":"7180959","type":"buy"},{"date":"1398348993","price":3090,"amount":0.0027,"tid":"7180961","type":"buy"},{"date":"1398348993","price":3091,"amount":0.0466,"tid":"7180963","type":"buy"}],"elapsed":"0.752ms"}
MD5下字符串 每次比较MD5后的结果
######为什么要MD5呢?我直接比较字符串不行么?######+1######MD5下字符串 每次比较MD5后的结果
从页面抓取过来应该是序列化的json吧,直接对比字符串不行嘛? 如果是对象格式,用JSON.stringify序列化一下再对比。
顺便问下楼主,如果data数组里面两个元素交换了顺序,算不算是数据变化呢?如果这种不算数据变化,那任何对比字符串的方式都白瞎了
######这里面的数据是会更新的,会返回最新的几十笔交易数据,若我每10秒读取一次,数据有可能全部刷新,有可能部分跟新,还有可能不变。。但是我需要每次读取将数据存储起来,存储起来的是新数据,以前存过的便不用存了。。但是每一个判断准则,所以好头疼。######做两种查询
一种结果里面带个"update time",返回个时间戳
一种是这种查询整套数据的
从流量和响应来说都好
######回复 @登峰 : 两种查询.一种是查询数据最新更新时间,如果后端前端一致就不必发送获取更新数据的请求. 否则如果有更新则从另外一种查询返回更新过的整套数据, 不是返回所有数据.######查询整套数据?这样不太现实吧,要是我已经存储的数据量很大呢?时间间隔太小,几秒钟刷新读取一次,用时间戳没什么用吧。######MD5下字符串 每次比较MD5后的结果
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。