Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to handle comma separated objects in json? ( [object Object],[object Object] )
    text
    copied!<p>I'm new to this so please bear with me. I'm dealing with the Twitter API which relies heavily on JSON (and that's not a bad thing).</p> <p>Something that Twitter does is return some values as comma seperated objects. This seems to be isolated to the [entities] section, which enumerates links within a tweet.</p> <p>This is a function I'm using to reduce json to unordered lists. The section commented out of this code is what I need help with.</p> <pre><code>function buildULfromJSON(data){ var items = []; function recurse(json){ //declare recursion function items.push('&lt;ul&gt;'); // start a new &lt;ul&gt; $.each(json, function(key, val) { // iterate through json and test, treat vals accordingly if((val == '[object Object]') &amp;&amp; (typeof val == 'object')){ // this catches nested json lists items.push('&lt;li&gt;[' + key + '] =&gt;&lt;/li&gt;'); // adds '[key] =&gt;' recurse(val); // calls recurse() to add a nested &lt;ul&gt; }else if(typeof(val)=='string'){ // catch string values items.push('&lt;li&gt;[' + key + '] = \"' + val + '\"&lt;/li&gt;'); // add double quotes to &lt;li&gt; item }/* else if(typeof(val) == 'object'){ // this throws exception in jquery.js $.each(val, function(){ // when val contains [object Object],[object Object] items.push('&lt;li&gt;[' + key + '] =&gt;&lt;/li&gt;'); // need to test for and process recurse(val); // comma seperated objects }); } */else{ items.push('&lt;li&gt;[' + key + '] = ' + val + '&lt;/li&gt;'); // non string, non object data (null, true, 123, .etc) } }); items.push('&lt;/ul&gt;'); // close &lt;/ul&gt; } // end recursion function recurse(data); // call recursion return items.join(''); // return results } // end buildULfromJSON() </code></pre> <p>Here is snippet of example output where the tweet contains one hashtag, two user mentions, and three urls. Those items are returned as a comma seperated list of objects (json data). I'm at a complete loss how to tackle this. Any direction you guys could provide would be excellent.</p> <p>Note the [text] string. It helps to put the [entities] section in context.</p> <pre><code>&lt;snippet&gt; [text] = "#Hashtag @PithyTwits @LuvsIt2 http://link1.com http://link2.com http://link3.com" [retweet_count] = 0 [entities] =&gt; [hashtags] =&gt; [0] =&gt; [text] = "Hashtag" [indices] = 0,8 [user_mentions] = [object Object],[object Object] [urls] = [object Object],[object Object],[object Object] [in_reply_to_screen_name] = null [in_reply_to_status_id_str] = null &lt;/snippet&gt; </code></pre> <p>My big issue at this point is that I don't know how to test for these lists without giving jquery.js fits. Once I do know how to isolate these lists in code, string functions for dealing with comma separated lists don't sound like the perfect fit... Any advice would be welcomed.</p> <p>Thank You,</p> <p>Skip</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload