如何显示由序列化数据组成的数组?

时间:2017-06-17 09:04:01

标签: javascript php ajax serialization

我从数据库中获取一条看起来像这样的记录。

>>> sum([asset['cells'] for asset in assets])

我设法获取数据并将其显示在页面上,但在迭代Array ( [data] => Array ( [creation_time] => 1497617542590 [is_marks_range_visible] => 1 [is_description_visible] => [is_grade] => [classes] => [is_grade_visible] => [grades] => [is_points] => 1 [is_description] => [school_id] => 28 [is_points_visible] => 1 [name] => CBSE Test [id] => 30 [grade_system_json] => [{"id":0,"min_marks":85,"max_marks":100,"grade":null,"description":null,"points":10.0},{"id":0,"min_marks":80,"max_marks":89,"grade":null,"description":null,"points":9.0}] [board] => CBSE ) [status] => success ) 数据时遇到问题。我想遍历那些序列化的数据。

我该怎么做?

2 个答案:

答案 0 :(得分:0)

制作一个将在阵列上运行的foretch循环并制作一个" if"值条件== grade_system_json,在内部做另一个将回显蚀刻值

的预测

但是说真的,我希望你不是以这种凌乱的方式工作,你在这里发布的关联阵列很难阅读

答案 1 :(得分:0)

您需要解码存储在grade_system_json密钥中的JSON,然后您将有一个数组进行迭代。假设您的数据存储在变量$obj中,它将如下所示:

$arr = json_decode($obj["data"]["grade_system_json"], true);

foreach ($arr as $elem) {
    // output some values. Adapt as needed:
    echo "id: {$elem["id"]}, min_marks: {$elem["min_marks"]}\n";
}