Path: csiph.com!aioe.org!.POSTED!not-for-mail From: =?UTF-8?Q?Arne_Vajh=c3=b8j?= Newsgroups: comp.lang.java.programmer Subject: Re: Function to explode not working... Need some help please. Date: Sun, 7 Feb 2016 12:33:09 -0500 Organization: Aioe.org NNTP Server Lines: 58 Message-ID: References: NNTP-Posting-Host: ANasIS7Js9OyLQwgloeBLQ.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 X-Notice: Filtered by postfilter v. 0.8.2 Xref: csiph.com comp.lang.java.programmer:33643 On 2/7/2016 3:32 AM, hazael00@gmail.com wrote: > I'm using Kimono to extract some data and create an API: > > { > "name": "site update", > "count": 4, > "frequency": "Manual Crawl", > "version": 1, > "newdata": true, > "lastrunstatus": "success", > "thisversionstatus": "success", > "thisversionrun": "Sun Feb 07 2016 05:13:26 GMT+0000 (UTC)", > "results": { > "collection1": [ > { > "title": { > "href": "http://www.tvtrailers.com/scenes/view/id/9418/title-1/", > "text": "Title 1" > }, > "pubDate": "February 6, 2016", > "index": 1, > "url": "http://www.tvtrailers.com/home/" > }, > I'm trying to `GET` the value of `href` inside the `title` `element`, > then `explode` the `string` to obtain the id number (`9418`, `9422`, > `9358`, `9419` on the code above) and create a new property with just > the id number. > > Or, if is not possible to create a new property, then I would like > tojust replace all the `href` string and keep the id number instead of > the full `href` url. > > Here is the updated `function` I'm using with the code provided by > Trincot on the comments below: > > // main function > function addPostNumbers(data) { > for(var collection in data.results) { > data.results[collection].forEach(function(row) { > if (parts = row.title.href.match(/\/(\d+)\//)) { > row.title.post_number = parts[1]; > } > }); > } > } > > // call the main function > addPostNumbers(data); > > // write result in document. > document.write('
' + JSON.stringify(data, null, 2) + '
'); That does not look like Java. Arne