'Convert multidimensional json to array in js
I am trying to select each member by converting a multidimensional json stored in longtext format in mysql to an array in js, but it fails.
Here's what I've tried:
Get data from mysql and convert it to json format. from php
if( isset( $_GET ) ){
$id = $_GET['id'];
$conn = db_connect();
$id = mysql_fix_string( $conn, $id );
$result = $conn->query("select _usage from SVM where id='$id'")or die(mysqli_error( $conn ));
$rows = array();
while( $re = mysqli_fetch_assoc( $result ) ){
$re['_usage'] = n12br( $re['_usage']);
$re['_usage'] = html_entity_decode( $re['_usage']);
$re['_usage'] = stripslashes( $re['_usage'] );
$rows[] = $re;
}
print( json_decode( $rows ));
}
js
$(document).on('click', '.view-subtitle', function(e, ele){
const id = (this).attr("data-value");
$.ajax({ url:'connect_data.php',
type:'GET',
data:{id: id},
success: function(html){
const result = JSON.parse(html);
console.log( typeof( result ) );
console.log( result[0] );
console.log( result[0].subtitle );
console.log( typeof( result[0].subtitle ));
},
error: function(e){
alert(e.responseText);
} ,
return false;
});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

