duanlinpi0265 2019-05-14 17:43
浏览 41

从带有函数的JSON文件 - 到mysql - 如何编写好的代码

I am rewritting function to get data from Json file to mysql. I have a bug in my code and I don't know where. If you can looking to function and tell me where do I do something wrong, I will be very happy.

json:

[{
"title":"Dumb Ways to Die 3 World Tour","gameType":"html5","description":"Play mini games featuring the characters from Dumb Ways to Die.

Dumb Ways to Die is a worldwide brand with over 300 million downloads on Apple App Store and Google Play combined.

Test your reflexes in this challenging series of mini games, where a milisecond can make the difference between winning and losing.

Score coins for each challenge, and use the to repair the once great town of Dumbville.",
"instructions":"Play mini games featuring the characters from Dumb Ways to Die.",
"url":"https://zxxcom/a91f360648334bc988222f1aff557c4e/",
"width":540,
"height":960,
"assetList":[{"name":"https://zxxcom/a91f360648334bc988222f1aff557c4e-512x340.jpeg"},{"name":"https://zxx.com/a91f360648334bc988222f1aff557c4e-512x512.jpeg"},{"name":"https://zxx.com/a91f360648334bc988222f1aff557c4e-512x384.jpeg"},{"name":"https://zxx.com/a91f360648334bc988222f1aff557c4e-1280x720.jpeg"},{"name":"https://zxx.com/a91f360648334bc988222f1aff557c4e-1280x550.jpeg"}],

"categoryList":[{"name":"Arcade"},{"name":"Sports"}],
"tagList":[{"name":"box2d"},{"name":"brain"},{"name":"brand"} ,{"name":"cute"},{"name":"endless"},{"name":"physi cs"},{"name":"simulation"},{"name":"cognitive"}],
"bundleList":[]},

code:

public function getParameterMap()
{
    return [
        'file' => 'url',
        'category' => ['categoryList']['name'],
        'thumbnail' => ['assetList']['name'],
        'tags' => ['tagList']['name'],
        'name' => 'title'
    ];
}

/**
* @param FeedGame $game
* @param $feedData
* @return mixed
*/
public function filterGame(FeedGame $game, $feedData)
{
    $game->setProviderId(substr(md5($feedData->name), 0, 5));
    $game->setCategory(array([($feedData->categoryList->name)]));
    $game->setThumbnail(array([($feedData->assetList->name)]));
    $name = $feedData->title;
    $description = $feedData->description;
    $game->setTags(array([($feedData->tagList->name)]));
}

After add data to mysql - in my base I see in category column – "Array". In tags column and thumbnail column, I see "Array" too.

In function filterGame - here I have something wrong, and I don't know, how to write it. Json file has array in array, and I don't know how to appeal to it.

Can you help me with this?

I want to have in mysql - thumbnail 512x512 and first category from categoryList (json), and all list of tags, with " , " after each tag.

Ps - sorry for my english - I learned it myself, and probably I do a lot of mistakes.

var_dump:

array (
  0 => 
  array (
    'title' => 'Dumb Ways to Die 3 World Tour',
    'gameType' => 'html5',
    'description' => 'Play mini games featuring the characters from Dumb Ways to Die.

Dumb Ways to Die is a worldwide brand with over 300 million downloads on Apple App Store and Google Play combined.

Test your reflexes in this challenging series of mini games, where a milisecond can make the difference between winning and losing.

Score coins for each challenge, and use the to repair the once great town of Dumbville.',
    'instructions' => 'Play mini games featuring the characters from Dumb Ways to Die.',
    'url' => 'https://zxx.com/a91f360648334bc988222f1aff557c4e/',
    'width' => 540,
    'height' => 960,
    'assetList' => 
    array (
      0 => 
      array (
        'name' => 'https://zxx.com/a91f360648334bc988222f1aff557c4e-512x340.jpeg',
      ),
      1 => 
      array (
        'name' => 'https://zxx.com/a91f360648334bc988222f1aff557c4e-512x512.jpeg',
      ),
      2 => 
      array (
        'name' => 'https://zxx.com/a91f360648334bc988222f1aff557c4e-512x384.jpeg',
      ),
      3 => 
      array (
        'name' => 'https://zxx.com/a91f360648334bc988222f1aff557c4e-1280x720.jpeg',
      ),
      4 => 
      array (
        'name' => 'https://zxx.com/a91f360648334bc988222f1aff557c4e-1280x550.jpeg',
      ),
    ),
    'categoryList' => 
    array (
      0 => 
      array (
        'name' => 'Arcade',
      ),
      1 => 
      array (
        'name' => 'Sports',
      ),
    ),
    'tagList' => 
    array (
      0 => 
      array (
        'name' => 'box2d',
      ),
      1 => 
      array (
        'name' => 'brain',
      ),
      2 => 
      array (
        'name' => 'brand',
      ),
      3 => 
      array (
        'name' => 'cute',
      ),
      4 => 
      array (
        'name' => 'endless',
      ),
      5 => 
      array (
        'name' => 'physics',
      ),
      6 => 
      array (
        'name' => 'simulation',
      ),
      7 => 
      array (
        'name' => 'cognitive',
      ),
    ),
    'bundleList' => 
    array (
    ),
  ),
  1 => 
  array (
    'title' => 'HeX PuzzleGuys',
    'gameType' => 'html5',
    'description' => 'Connect 4 hexagons of the same color, it\'s that simple!',
    'instructions' => 'Drag and drop pieces and connect at least 4 hexagons of the same color. When you get out of space, the game is over (luckily, you can always restart it!)',
    'url' => 'https://zxx.com/657afaed169b45b6a678637be1912c65/',
    'width' => 800,
    'height' => 600,
    'assetList' => 
    array (
      0 => 
      array (
        'name' => 'https://zxx.com/657afaed169b45b6a678637be1912c65-512x384.jpeg',
      ),
      1 => 
      array (
        'name' => 'https://zxx.com/657afaed169b45b6a678637be1912c65-512x512.jpeg',
      ),
      2 => 
      array (
        'name' => 'https://zxx.com/657afaed169b45b6a678637be1912c65-512x340.jpeg',
      ),
    ),
    'categoryList' => 
    array (
      0 => 
      array (
        'name' => 'Puzzle',
      ),
    ),
    'tagList' => 
    array (
      0 => 
      array (
        'name' => 'hexagon',
      ),
      1 => 
      array (
        'name' => 'connect-4',
      ),
    ),
    'bundleList' => 
    array (
    ),
  ),
)
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥60 求一个简单的网页(标签-安全|关键词-上传)
    • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
    • ¥15 基于卷积神经网络的声纹识别
    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP