嘟嘟社区

不懂就问:Json解析大佬请进


访问接口返回一个类似这样的:jQuery112309021942920700254_1639277232768(json字符串) ,然后我要解码这个json对象里面的东西,每次都要写个函数,取()中间的json字符串,然后再解析。  你们是不是这样搞的? 这样不是很麻烦吗?  为什么网站不直接返回一个 json字符串就行了  还要加前面那堆东西jQuery112309021942920700254_1639277232768,,,它网站自己不是也要解析的吗?

返回的详细文本:
jQuery112309021942920700254_1639277232768({"data":{"list":[{"art_code":"AN202112101533791353","codes":[{"ann_type":"A,SHA","inner_code":"42105843172747","market_code":"1","short_name":"江苏租赁","stock_code":"600901"}],"columns":[{"column_code":"001002007004003","column_name":"股东/实际控制人股份减持"},{"column_code":"003014","column_name":"其它"}],"display_time":"2021-12-10 18:04:37:269","eiTime":"2021-12-10 18:06:18:000","language":"0","notice_date":"2021-12-11 00:00:00","title":"600901:江苏租赁:5%以下股东集中竞价减持股份结果公告","title_ch":"600901:江苏租赁:5%以下股东集中竞价减持股份结果公告","title_en":""},{"art_code":"AN202112081533523464","codes":[{"ann_type":"A,SHA","inner_code":"42105843172747","market_code":"1","short_name":"江苏租赁","stock_code":"600901"}],"columns":[{"column_code":"001002006005","column_name":"签订协议"}],"display_time":"2021-12-08 18:01:14:343","eiTime":"2021-12-08 18:02:36:000","language":"0","notice_date":"2021-12-09 00:00:00","title":"600901:江苏租赁:关于签署可转换公司债券募集资金专户存储三方监管协议的公告","title_ch":"600901:江苏租赁:关于签署可转换公司债券募集资金专户存储三方监管协议的公告","title_en":""}],"page_index":1,"page_size":2,"total_hits":362},"error":"","success":1})

这个是给jQuery解析的,用其他程序解析就要先处理一下
get 请求参数可以把 callback什么参数注解掉
可能jsonp吧,看看content-type是不是javascript而不是json,直接当js运行的,不需要解析
这是jsonp
这是jsonp ,用jsonp的方式请求
会在获取结果后自动调用函数
不管你用的是jQuery还是Vue,都有处理jsonp的办法的。