Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP or JQUERY JSON Handling
    primarykey
    data
    text
    <p>I have a simple JSON StdClass Object from a PHP, and I wish to format it into a table/list/div and eliminate other keys and values in the process. The JSON looks like this:</p> <pre><code>stdClass Object ( [msc] =&gt; 150 [number] =&gt; 309 [status] =&gt; OK [msc_mcc] =&gt; 652 [imsi] =&gt; 652010154107728 [mcc] =&gt; 652 [operator_country] =&gt; Botswana [msc_operator_name] =&gt; MSC [msc_operator_country] =&gt; Botswana [msc_mnc] =&gt; 01 [mnc] =&gt; 01 [id] =&gt; 1072540715 [msc_location] =&gt; [operator_name] =&gt; MSC ) </code></pre> <p>I have tried PHP and did make a table, but the problem is I need to pick certain values other that the whole body, and also I need to eliminate empty values</p> <pre><code>function print_nice($elem,$max_level=10,$print_nice_stack=array()){ if(is_array($elem) || is_object($elem)){ if(in_array($elem,$print_nice_stack,true)){ echo "&lt;font color=red&gt;RECURSION&lt;/font&gt;"; return; } $print_nice_stack[]=&amp;$elem; if($max_level&lt;1){ echo "&lt;font color=red&gt;nivel maximo alcanzado&lt;/font&gt;"; return; } $max_level--; echo "&lt;table class='table table-bordered table-striped'&gt;"; if(is_array($elem)){ echo '&lt;tr&gt;&lt;th colspan=2&gt;&lt;strong&gt;&lt;font&gt;&lt;h3&gt;Results, with love&lt;/h3&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/th&gt;&lt;/tr&gt;'; }else{ echo '&lt;tr&gt;&lt;th colspan=2 class=hdrs&gt;&lt;strong&gt;'; echo '&lt;font color=white&gt;OBJECT Type: '.get_class($elem).'&lt;/font&gt;&lt;/strong&gt;&lt;/th&gt;&lt;/tr&gt;'; } $color=0; foreach($elem as $k =&gt; $v){ if($max_level%2){ $rgb=($color++%2)?"#f5f5f5":"#efeeee"; }else{ $rgb=($color++%2)?"#f5f5f5":"#efeeee"; } echo '&lt;tr&gt;&lt;td valign="top" style="width:40px;background-color:'.$rgb.';"&gt;'; echo '&lt;strong&gt;'.$k."&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;"; print_nice($v,$max_level,$print_nice_stack); echo "&lt;/td&gt;&lt;/tr&gt;"; } echo "&lt;/table&gt;"; return; } if($elem === null){ echo "&lt;font color=green&gt;NULL&lt;/font&gt;"; }elseif($elem === 0){ echo "0"; }elseif($elem === true){ echo "&lt;font color=green&gt;TRUE&lt;/font&gt;"; }elseif($elem === false){ echo "&lt;font color=green&gt;FALSE&lt;/font&gt;"; }elseif($elem === ""){ echo "&lt;font color=green&gt;EMPTY STRING&lt;/font&gt;"; }else{ echo str_replace("\n","&lt;strong&gt;&lt;font color=red&gt;*&lt;/font&gt;&lt;/strong&gt;&lt;br&gt;\n",$elem); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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