Title: get field echoing json
Last modified: August 31, 2016

---

# get field echoing json

 *  Resolved [thejohnnyduke](https://wordpress.org/support/users/thejohnnyduke/)
 * (@thejohnnyduke)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/get-field-echoing-json/)
 * Hi,
 * I’ve a function to return the table inside a repeater field with the following
   code:
 *     ```
       if ( have_rows( $repeater_name ) ) {
       	while ( have_rows( $repeater_name ) ) { the_row();
       		$table = get_sub_field('content_table'));
       	}
       }
       ```
   
 * If I var dump the table sub_field I get:
 * `string(69) "{"p":{"o":{"uh":0}},"c":[{"p":""}],"h":[{"c":""}],"b":[[{"c":"aa"}]]}"`
 * Everything is ok, except that, using the documentation provided I expected to
   be an array, so I can use the cycles described in the plugin description.
 * Am I doing something wrong?
 * Thanks
 * [https://wordpress.org/plugins/advanced-custom-fields-table-field/](https://wordpress.org/plugins/advanced-custom-fields-table-field/)

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Plugin Author [Johann Heyne](https://wordpress.org/support/users/jonua/)
 * (@jonua)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/get-field-echoing-json/#post-7054006)
 * Your code is ok.
 * May there went something wrong with the PHP json_decode() function in your server
   environment. Please test the following code that should decode the JSON string
   to an array…
 *     ```
       var_dump( json_decode( '{"p":{"o":{"uh":0}},"c":[{"p":""}],"h":[{"c":""}],"b":[[{"c":"aa"}]]}', true ) );
       ```
   
 * It should output this…
 *     ```
       array(4) { ["p"]=> array(1) { ["o"]=> array(1) { ["uh"]=> int(0) } } ["c"]=> array(1) { [0]=> array(1) { ["p"]=> string(0) "" } } ["h"]=> array(1) { [0]=> array(1) { ["c"]=> string(0) "" } } ["b"]=> array(1) { [0]=> array(1) { [0]=> array(1) { ["c"]=> string(2) "aa" } } } }
       ```
   
 *  Thread Starter [thejohnnyduke](https://wordpress.org/support/users/thejohnnyduke/)
 * (@thejohnnyduke)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/get-field-echoing-json/#post-7054027)
 * Hi Johann, thanks for the quick reply! 🙂
 * The code you provided outputted the correct array (as you wrote).
 * This is my complete code:
 * single-post page (inside the loop):
 *     ```
       $product = new SG_products;
       $product->getProductRepeater('measurements', 'content_table', get_the_ID()));
       ```
   
 * SG_products class:
 *     ```
       public function getProductRepeater( $repeater_name, $field_name, $product_id ) {
       	if ( have_rows( $repeater_name ) ) {
       		$descriptions = array();
       		while ( have_rows( $repeater_name ) ) { the_row();
       			foreach (get_sub_field('taxonomy_association') as $taxonomy_group) {
       				$descriptions[$taxonomy_group][$field_name]	= $this->getTable( $field_name );
       			}
       		}
       	}
       	return $descriptions;
       }
   
       private function getTable( $field_name ) {
       	$field = get_sub_field($field_name);
       	var_dump($field);
       	$table = '<table>';
       	foreach ( $field['body'] as $tr ) {
       		$table .= '<tr>';
       		foreach ( $tr as $td ) {
       			$table .= '<td>';
       			$table .= $td['c'];
       			$table .= '</td>';
       		}
       		$table .= '</tr>';
       	}
       	$table .= '</table>';
       	return $table;
       }
       ```
   
 * The output of the var_dump is the json I wrote in the first post.
    Any thoughts?
 * Thanks for the help!
 *  Plugin Author [Johann Heyne](https://wordpress.org/support/users/jonua/)
 * (@jonua)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/get-field-echoing-json/#post-7054043)
 * There are to many `)` at the end in line…
 *     ```
       $product->getProductRepeater('measurements', 'content_table', get_the_ID()));
       ```
   
 * Anyway, I tested this class and it worked as expected.
 * Strange
 *  Thread Starter [thejohnnyduke](https://wordpress.org/support/users/thejohnnyduke/)
 * (@thejohnnyduke)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/get-field-echoing-json/#post-7054059)
 * Hi Johann,
 * I’ve found the error. I’m using a local wp install but with an remote database(
   dev env). I forgot to sync the plugin folder…
    In the admin area everything was
   ok (since I access it remotely), but testing locally, the wp installation didn’t
   find the plugin, hence the error…
 * Sorry for the inconvenience, I need the weekend asap 😛
 * Thanks once again and keep up the great work!
 *  Plugin Author [Johann Heyne](https://wordpress.org/support/users/jonua/)
 * (@jonua)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/get-field-echoing-json/#post-7054061)
 * Nice, this is a topic for the plugins trouble shouting page.
    Thanks!

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘get field echoing json’ is closed to new replies.

 * ![](https://ps.w.org/advanced-custom-fields-table-field/assets/icon-256x256.png?
   rev=1962986)
 * [Table Field Add-on for ACF and SCF](https://wordpress.org/plugins/advanced-custom-fields-table-field/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/advanced-custom-fields-table-field/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/advanced-custom-fields-table-field/)
 * [Active Topics](https://wordpress.org/support/plugin/advanced-custom-fields-table-field/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/advanced-custom-fields-table-field/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/advanced-custom-fields-table-field/reviews/)

## Tags

 * [ACF](https://wordpress.org/support/topic-tag/acf/)
 * [json](https://wordpress.org/support/topic-tag/json/)
 * [table](https://wordpress.org/support/topic-tag/table/)

 * 5 replies
 * 2 participants
 * Last reply from: [Johann Heyne](https://wordpress.org/support/users/jonua/)
 * Last activity: [10 years, 4 months ago](https://wordpress.org/support/topic/get-field-echoing-json/#post-7054061)
 * Status: resolved