1:开始没想分享的,后来看到有大佬分享如何使用Chrom的工具进行调试,哈哈哈哼,我就借着他的博客写一下我摸索的如何进行前后台数据交互吧(注:反正是自己瞎 捣鼓出来的,也许适合我,and我脑补一下吧,日后忘记了还可以看看,如果不适合看到的各位的话,请绕行,勿喷,谢谢):那位大佬的博客链接(拉到最下面可以看到他的系列链接,哈哈哈哼):http://www.cnblogs.com/st-leslie/p/8196493.html
2:当数据传到你的控制层,然后传到了前台,这个时候是个人就想着进行解析数据,但是你传过来的数据格式是什么样子的,解析方式千变万化,所以这个时候使用Chrom工具进行调试,比海量百度强很多(因为如果没有那位好心的大佬贴出来自己源码的话,哈哈哈,你搜不到啊):
3:第一种,我控制层传过来的是如此数据格式的,如下所示:
后台打印如下所示,这个时候我想传给前台Json格式的,你可以去Json在线验证一下是否是Json格式的哦,如何转换Json就不贴了吧,百度一搜还真是一大推,而且之前也贴过了,这里主要讲如何进行Chrom调试吧:
JSON格式的数据:{"list":[{"bookSum":,"bookAuthor":"别先生","bookSortName":"","bookMark":"","bookPublish":"科学出版社","bookId":,"bookPrice":56.0,"bookType":"计算机类别","bookSortId":,"bookName":"Storm"},{"bookSum":,"bookAuthor":"别先生","bookSortName":"","bookMark":"","bookPublish":"科学出版社","bookId":,"bookPrice":25.0,"bookType":"数学类","bookSortId":,"bookName":"hadoop"},{"bookSum":,"bookAuthor":"别先生","bookSortName":"","bookMark":"","bookPublish":"科学出版社","bookId":,"bookPrice":25.0,"bookType":"数学类","bookSortId":,"bookName":"C"},{"bookSum":,"bookAuthor":"别先生","bookSortName":"","bookMark":"","bookPublish":"科学出版社","bookId":,"bookPrice":25.0,"bookType":"数学类","bookSortId":,"bookName":"C++"},{"bookSum":,"bookAuthor":"陈先生","bookSortName":"","bookMark":"","bookPublish":"科学出版社","bookId":,"bookPrice":25.0,"bookType":"数学类","bookSortId":,"bookName":"Java"}]}
4:传到前台打印一下,是这个B样子的:
5:然后呢,需要对数据进行解析,如果你不知道怎么解析值,百度或者自己调试,我是这么调试的:
在Ajax返回回来的地方打了一个断点,然后呢,我这里是一刷新页面就卡在这里了,等你进行下一步或者调试操作:
6:然后呢,切换到控制台Console,因为我返回的是结果名称是result,你在控制台直接打res,会自动提示的,然后按table键弹出来你想要的;
7:然后呢,你点. 一下(注意是.哦),然后会弹出你想要的,比如我的list,是不是有点明白我在讲什么了,哈哈哈哼。
我这里是根据result.list,然后再根据自己写的获取json字符串格式长度(获取json格式字符串长度的方法百度一下很多的哦);
获取到的json格式字符串长度如下所示:
8:重点就是如何解析自己的json格式字符串了,如下所示(需要注意的是.以后是Tab键不是Enter键,我都是手欠,哈哈哈哼,翻看上一条指令是上箭头):
如下所示就解析出来,你该以何种格式来解析自己的Json字符串了,不知道有没有小伙伴听清楚了:
9:为了避免有的小伙伴,说,我靠,你说的啥,我再演示另一种,自己摸索的B玩意,总之吧,希望帮助到看到的小伙伴:
这次数据格式是这样的,去Json在线解析,是正确的Json格式的(由于没有贴代码,如果你后台传到前台的数据格式不一样,前台解析就出现差异,但是万变不离其宗,这里只说了方法,没有贴代码,还请看到的小伙伴见谅)。
JSON格式的数据:[{"bookId":,"bookName":"Storm","bookAuthor":"别先生","bookPrice":56.0,"bookType":"计算机类别","bookPublish":"科学出版社","bookSum":,"bookMark":null,"bookSortId":,"bookSortName":null},{"bookId":,"bookName":"hadoop","bookAuthor":"别先生","bookPrice":25.0,"bookType":"数学类","bookPublish":"科学出版社","bookSum":,"bookMark":null,"bookSortId":,"bookSortName":null},{"bookId":,"bookName":"C","bookAuthor":"别先生","bookPrice":25.0,"bookType":"数学类","bookPublish":"科学出版社","bookSum":,"bookMark":null,"bookSortId":,"bookSortName":null},{"bookId":,"bookName":"C++","bookAuthor":"别先生","bookPrice":25.0,"bookType":"数学类","bookPublish":"科学出版社","bookSum":,"bookMark":null,"bookSortId":,"bookSortName":null},{"bookId":,"bookName":"Java","bookAuthor":"陈先生","bookPrice":25.0,"bookType":"数学类","bookPublish":"科学出版社","bookSum":,"bookMark":null,"bookSortId":,"bookSortName":null}]
这里就说这两种吧,总之,自己多摸索,万变不离其宗,哈哈哈哼,在大佬面前卖弄了,好久没主动发到博客园首页了,今天发一次吧,争取不被一分钟从博客园撤掉,哈哈哈哼(之前见大佬,说发布到博客园首页的博客被撤,愤愤不平,还专一写博对博客园,哈哈哈哼,我感觉自己写博客,也算是一种修身养性,我是不计较这些,自己写的被看到不被看到,自己提升才重要,对那些想打广告的,也许只想着曝光率吧,哈哈哈哼。2017年过去了,看了不少写总结的,看到大佬们,羞愧难当。我是没东西写,这里希冀一下吧,希望自己本命年,可以红红火火,兜里多进毛爷爷吧。也希冀看到此篇博客的小伙伴2018红红火火,兜里也多进毛爷爷,技术更上一层楼,哈哈哈哼,没看到的小伙伴就不祝福了哈)。
停更......