Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 解析<;的json数据;突出显示>;标记以高亮显示字段中的文本_Javascript_Jquery_Json_Solr - Fatal编程技术网

Javascript 解析<;的json数据;突出显示>;标记以高亮显示字段中的文本

Javascript 解析<;的json数据;突出显示>;标记以高亮显示字段中的文本,javascript,jquery,json,solr,Javascript,Jquery,Json,Solr,并将其解析为 $.getJSON("http://192.168.1.9:8983/solr/db/select/?wt=json&&start=0&rows=20&q="+newquery+"&sort=price asc&hl=true&hl.fl=description&hl.usePhraseHighlighter=true&json.wrf=?", function(newresult){ 及 假设响应始终为文本

并将其解析为

$.getJSON("http://192.168.1.9:8983/solr/db/select/?wt=json&&start=0&rows=20&q="+newquery+"&sort=price asc&hl=true&hl.fl=description&hl.usePhraseHighlighter=true&json.wrf=?", function(newresult){


假设响应始终为文本,并且只有要突出显示的元素包含在
标记中,并且只有一个标记,则可以执行以下操作:

 $.each(newresult.highlighting, function(i,hitem){

您的JSON无效:
“文档”:[1.{
文档
突出显示
不是标记,它们是属性。您现在想做什么?请澄清您的问题。@Felix Kling:我已经编辑了JSON,现在它是有效的。我的问题是我想得到“优雅”在我的搜索结果中突出显示,如果我将突出显示属性解析到elegant@FelixKling:现在我的问题是如何进入,搜索结果是哪一次?那些在
文档中的?@Felix Kling:是的,搜索结果在文档中Elix Kling:我可以使用hitem.description[0],因为描述在“8252”中,我无法获得此描述:(@Romi:这应该可以正常工作。
i
应该是
8252
hitem
对应的元素。请参阅:您使用了JSON.stringify((hitem.description[0]),这是什么。Felix Kling:当我将警报(word)放在$.each(newresult.highlighting,function(i,hitem)中时){,那么我的jsp页面不工作。脚本没有显示任何错误,但它不是running@Romi:我刚刚尝试了一些功能。在没有它的情况下也可以使用:。您必须在定义它之后放置
警报(word)
$.each(newresult.response.docs, function(i,item){
 $.each(newresult.highlighting, function(i,hitem){
var highlight = {};

$.each(newresult.highlighting, function(i, hitem){
    var match = hitem.description[0].match(/<em>(.*?)<\/em>/);
    highlight[i] = match[1];
});

$.each(newresult.response.docs, function(i, item){
    var word = highlight[item["UID_PK"]];
    var result = item.description.replace(new RegExp(word, 'g'), '<em>' + word + '</em>');
    // do something with the result
});
item.description.replace(word, '<em>' + word + '</em>');