您现在的位置 > 首页>知识问答 >

求助码农http请求相关问题

点击图片查看下一页
查看原图
更新:07-15     编辑:     来源:    
  • http://fund.eastmoney.com/Data/F ... ;text=&sort=zdf,desc&page=1,10&dt=1425897162484&atfc=
    我对上面的网址发起http请求后,获得的结果是
    var db={chars:["a","b","c","d","f","g","h","j","m","n","p","q","r","s","t","w","x","y","z"],datas:[["001777","德邦多元回报灵活配置混合A","DBDYHBLHPZHHA","1.2458","1.2458","1.1863","1.1863","0.0595","5.02","暂停申购","开放赎回","","4","0","1","","1","0.15%","0.15%","1","1.50%"],["290004","泰信优质生活混合","TXYZSHHH","1.0011","1.8148","0.9832","1.7969","0.0179","1.82","开放申购","开放赎回","","1","0","2","","1","0.15%","0.15%","1","1.50%"],["519191","万家新利灵活配置混合","WJXLLHPZHH","1.0925","1.3741","1.0764","1.3580","0.0161","1.50","开放申购","开放赎回","","1","0","3","","1","0.06%","0.06%","1","0.60%"],["502023","鹏华钢铁分级","PHGTFJ","1.0240","1.05","1.01","1.0360","0.0140","1.39","开放申购","开放赎回","","1","0","4","","1","0.12%","0.12%","1","1.20%"],["168203","中融国证钢铁行业指数分级","ZRGZGTHYZSFJ","0.9130","0.5620","0.9010","0.5550","0.0120","1.33","开放申购","开放赎回","","1","0","5","","0","0.00%","","",""],["290011","泰信中小盘精选混合","TXZXPJXHH","1.9340","2.1940","1.9090","2.1690","0.0250","1.31","开放申购","开放赎回","","1","0","6","","1","0.15%","0.15%","1","1.50%"],["161721","招商沪深300地产指数分级","ZSHS300DCZSFJ","0.7930","1.3560","0.7830","1.3460","0.01","1.28","开放申购","开放赎回","","1","0","7","","1","0.10%","0.10%","1","1.00%"],["001614","东方区域发展混合","DFQYFZHH","1.0065","1.0065","0.9942","0.9942","0.0123","1.24","开放申购","开放赎回","","1","0","8","","1","0.15%","0.15%","1","1.50%"],["519185","万家精选混合","WJJXHH","1.7774","2.3524","1.7557","2.3307","0.0217","1.24","限大额","开放赎回","","1","0","9","","1","0.15%","0.15%","1","1.50%"],["164908","交银中证环境治理(LOF)","JYZZHJZLLOF","1.0720","1.0720","1.0590","1.0590","0.0130","1.23","开放申购","开放赎回","","1","0","10","","1","0.12%","0.12%","1","1.20%"]],count:["4269","1320","776","2173"],record:"4998",pages:"500",curpage:"1",indexsy:[0.60,0.35,0.50,],showday:["2017-04-10","2017-04-07"]}

    如果我要获取datas里边的数据,该怎么处理?如果没有var db=就是普通的json对象吧,这个该咋弄。。当成字符串去处理么?那具体该怎么做


    网友评论:

    替换掉之后也不是标准的json,key需要有引号,把所有,(.*):匹配到的内容替换成,"$1":


    没看懂,需不需要把conten-type换成query string
    对于 header["content-type"] 为 "application/x-www-form-urlencoded" 的数据,会将数据转换成 query string

    这不是json,是javaXcript对象,用rhino求值吧。

    现在想到的lowb方法是先把var db={chars:["a","b","c","d","f","g","h","j","m","n","p","q","r","s","t","w","x","y","z"],datas:[这部分截取了,反正无论什么参数这部分都是固定的,后面再用split(‘]’)截取,然后进行处理

    直接 db.datas[x][y] 不行吗


    我把结果typeof了,是字符串。。不是object

    eval?肯用的话

    后面没法split "]",因为中间的数组,[]的个数都是不确定的,怎么split

    直接用正则取得datas里面的内容,里面的内容是可以直接当json解码的

    为什么返回的是js。。
    你可以用eval,把返回的字符串整个eval(data)一下,然后由于已经有"var db="了,直接db就能获取整个object,db.datas就是你要的。


    哦,原来是JSONP,搜下就知道了吧

    var db;
    eval("db={chars:["a","b","c","d","f","g","h","j","m","n","p","q","r","s","t","w","x","y","z"],datas:[["001777","德邦多元回报灵活配置混合A","DBDYHBLHPZHHA","1.2458","1.2458","1.1863","1.1863","0.0595","5.02","暂停申购","开放赎回","","4","0","1","","1","0.15%","0.15%","1","1.50%"],["290004","泰信优质生活混合","TXYZSHHH","1.0011","1.8148","0.9832","1.7969","0.0179","1.82","开放申购","开放赎回","","1","0","2","","1","0.15%","0.15%","1","1.50%"],["519191","万家新利灵活配置混合","WJXLLHPZHH","1.0925","1.3741","1.0764","1.3580","0.0161","1.50","开放申购","开放赎回","","1","0","3","","1","0.06%","0.06%","1","0.60%"],["502023","鹏华钢铁分级","PHGTFJ","1.0240","1.05","1.01","1.0360","0.0140","1.39","开放申购","开放赎回","","1","0","4","","1","0.12%","0.12%","1","1.20%"],["168203","中融国证钢铁行业指数分级","ZRGZGTHYZSFJ","0.9130","0.5620","0.9010","0.5550","0.0120","1.33","开放申购","开放赎回","","1","0","5","","0","0.00%","","",""],["290011","泰信中小盘精选混合","TXZXPJXHH","1.9340","2.1940","1.9090","2.1690","0.0250","1.31","开放申购","开放赎回","","1","0","6","","1","0.15%","0.15%","1","1.50%"],["161721","招商沪深300地产指数分级","ZSHS300DCZSFJ","0.7930","1.3560","0.7830","1.3460","0.01","1.28","开放申购","开放赎回","","1","0","7","","1","0.10%","0.10%","1","1.00%"],["001614","东方区域发展混合","DFQYFZHH","1.0065","1.0065","0.9942","0.9942","0.0123","1.24","开放申购","开放赎回","","1","0","8","","1","0.15%","0.15%","1","1.50%"],["519185","万家精选混合","WJJXHH","1.7774","2.3524","1.7557","2.3307","0.0217","1.24","限大额","开放赎回","","1","0","9","","1","0.15%","0.15%","1","1.50%"],["164908","交银中证环境治理(LOF)","JYZZHJZLLOF","1.0720","1.0720","1.0590","1.0590","0.0130","1.23","开放申购","开放赎回","","1","0","10","","1","0.12%","0.12%","1","1.20%"]],count:["4269","1320","776","2173"],record:"4998",pages:"500",curpage:"1",indexsy:[0.60,0.35,0.50,],showday:["2017-04-10","2017-04-07"]}")
    var _data = db.datas;

    是这个意思吗


    我这个用不了eval的。。有替代方案么


    啥意思,可以发送HTTP请求并获得响应,但不能用js处理?是在什么语言环境?


    微信小程序没法用eval,虽然是用js



    0:
    "["003816","银华日利B","YHRLB","","","109.0140","111.57","","","开放申购","开放赎回","","","0","1","","","0.00%","","","""
    1
    :
    ",["000011","华夏大盘精选","HXDPJX","","","11.0470","15.1270","","","开放申购","开放赎回","","1","0","2","","1","0.15%","0.15%","1","1.50%""
    2
    :
    ",["070002","嘉实增长","JSZZ","","","9.5210","10.1620","","","开放申购","开放赎回","","1","0","3","","1","0.15%","0.15%","1","1.50%""
    3
    :
    ",["240008","华宝收益增长","HBSYZZ","","","5.9390","5.9390","","","开放申购","开放赎回","","1","0","4","","1","0.15%","0.15%","1","1.50%""
    4
    :
    ",["070006","嘉实服务增值行业","JSFWZZHY","","","5.6390","6.1490","","","开放申购","开放赎回","","1","0","5","","1","0.15%","0.15%","1","1.50%""
    5
    :
    ""
    6
    :
    ",count:["0","0","0","0""
    7
    :
    ","
    用slice+split出来的结果勉强能用?page我给了1,5.选取前5个,稍作处理的话,信息还是没丢的保留前5个元素,再对每个元素处理,再次split,然后join,就能用了吧?虽然low了点,



    JSON.parse(str.match("datas:(\\[(\\[.*?])*])")[1]);
    这样行?


    可以诶,正则表达式牛逼,我编译原理这学期重修呢


    能大致讲解下原理么,要写论文

    喷了,返回代码是怎么想的


    啥意思?我用楼上那个正则表达式很好啊


    我是指这个网站,为什么不直接传 json?正则表达式也只是刚好嵌套结构固定才能用。


    撒,我也不知道,网上找的,超级好用(我研究完那些参数意义,直接当数据库用了都。。而且还每天更新·),还免费,无敌了。。简直宝具。免费还强大就别纠结太多啦


    前面几楼已经说了 http://www.zhihu.com/question/19966531



    简略的regexp的写法是这样

      /datas:(\[\[.*?]])/g
    复制代码

    \[是转义,表示匹配"["这个字符,因为正则里[]是用来表示匹配组的
    ]没有转义是因为没有配对的[,认为是匹配"]"字符
    .表示匹配换行符除外的任意字符
    *表示重复0次或多次
    ?表示匹配0次或1次,但是*之后接?表示懒匹配,匹配尽可能短的字符串()是捕获组,其中匹配到的内容可以记忆,为什么要这个下面会说明

    因为data这个key的value是一个[[], [], ... , []]的Array,最简单的方法就是匹配data:之后出现的第一组[[和]]全部内容

    假设你取到的字符串str
      var reg = /datas:(\[\[.*?]])/g;
    复制代码

    JSON解析就可以这样
      JSON.parse(reg.exec(str)[1]);
    复制代码
    其中reg.exec(str)是一个Array表示匹配的结果,[0]是第一个匹配到的结果,[1],[2],...就是上面的捕获组内的内容,这里[1]就是正则表达式内第一组()内匹配到的内容

    想要具体了解可以到http://regexr.com/去测试你的正则表达式


    为啥最后一个]不用转义?哦看到了。。

相关推荐

精彩图集

一品图片网部分图片资源收集于互联网,如果侵犯了您的版权请来信告知,我们会及时处理和回复,邮件地址:
© 2021 一品图片网 版权所有 苏ICP备150288886号 | sitemap | 图片大全