如何将每个值串在一起以获得此查询结构,其中每个ISBN前面都带有"isbn:",而在第一个之后则用"OR"分隔https://www.google.com/search?btnG=Search+Books&tbm=bks&q=Springfield+isbn:1416549838+OR+isbn:068482535X+OR+isbn:0805093079+OR+isbn:0306810328解决方案从称为list的ISBN字符串数组开始:list.map(function(v){return "isbn:"+v;}).join("+OR+")关于建立您的ISBN列表,我理解是您的industryIdentifiers中的identifier道具(如果industryIdentifier是真诚的Array):var list = [];volumeInfo.industryIdentifiers.forEach(function(e,i){list.push(e.identifier);});您也可以一次构建最后一个字符串,而根本不构建数组,但这意味着需要额外的逻辑来防止插入额外的定界符(+OR+是定界符)var output = "";volumeInfo.industryIdentifiers.forEach(function(e,i){output += "isbn:"+e.identifier+"+OR+";});output.slice(0,-4); // clear out last +OR+I'd like to create a string of ISBNs from a JSON object to search multiple books in Google Books.I can get the ISBNs by parsing Google Books' JSON with this path:volumeInfo.industryIdentifiers[0].identifier(Here I'm doing that to get a simple book list: jsfiddle.net/LyNfX )How do I string together each value in order to get this query structure, where each ISBN is preceded by "isbn:", and after the first one they are separated by "OR" https://www.google.com/search?btnG=Search+Books&tbm=bks&q=Springfield+isbn:1416549838+OR+isbn:068482535X+OR+isbn:0805093079+OR+isbn:0306810328 解决方案 Starting from an array of ISBN strings called list: list.map(function(v){return "isbn:"+v;}).join("+OR+")As for building your list of ISBN's which I understand to be the identifier prop in your industryIdentifiers (if industryIdentifier is a bona fide Array):var list = [];volumeInfo.industryIdentifiers.forEach(function(e,i){list.push(e.identifier);});You could also just build the final string in one fell swoop and not build an array at all, but this means extra logic to prevent inserting an extra delimiter (+OR+ being the delimiter)var output = "";volumeInfo.industryIdentifiers.forEach(function(e,i){output += "isbn:"+e.identifier+"+OR+";});output.slice(0,-4); // clear out last +OR+ 这篇关于从jQuery中的JSON值创建字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
05-26 23:57
查看更多