PHP的json_decode输出cli

时间:2016-01-28 08:41:57

标签: php json

我尝试在php中解析控制台输出并从json格式解码,但得到错误=引用的对象属性名称

解析器本身是一个外部库,用python编写: https://github.com/Blizzard/heroprotocol

$ output - 包含此字符串: json_decode($ output)失败

如果有人能帮我找到解决方案来制作这个json_decode,我将感激不尽

{'m_cacheHandles': ['s2ma\x00\x00EU\x1f\x1b"\x8d\xdb\x1fr \\\xbf\xd4D\x05R\x87\x10\x0b\x0f9\x95\x9b\xe8\x16T\x81b\xe4\x08\x1e\xa8U\x11',
                's2ma\x00\x00EU\x1a\xd9L\x12n\xb9\x8aL\x1d\xe7\xb8\xe6\xf8\xaa\xa1S\xdb\xa5+\t\xd3\x82^\x0c\x89\xdb\xc5\x82\x8d\xb7\x0fv',
                's2ma\x00\x00EU\x92\xd8\x17D\xc1D\x1b\xf6(\xedj\xb7\xe9\xd1\x94\x85\xc8`\x91M\x8btZ\x91\xf65\x1f\xf9\xdc\xd4\xe6\xbb',
                's2ma\x00\x00EU\xa1\xe9\xab\xcd?\xd2PS\xc9\x03\xab\x13R\xa6\x85u7(K2\x9d\x08\xb8k+\xe2\xdeI\xc3\xab\x7fC',
                's2ma\x00\x00EU[Q\xb6\xcb+e\x93\xa9\xa1\xb0\xd8y\x10;\xd7J\x9b\x0c\x15=u\xe6\xa2\xcc\x10\xa9N\xd1\xba\xe9\xc6&'],
 'm_campaignIndex': 0,
 'm_defaultDifficulty': 7,
 'm_description': '',
 'm_difficulty': '',
 'm_gameSpeed': 4,
 'm_imageFilePath': '',
 'm_isBlizzardMap': True,
 'm_mapFileName': '',
 'm_miniSave': False,
 'm_modPaths': None,
 'm_playerList': [{'m_color': {'m_a': 255, 'm_b': 255, 'm_g': 92,     'm_r': 36},
                   'm_control': 2,
                   'm_handicap': 100,
                   'm_hero': 'Jaina',
                   'm_name': 'Gela',
                   'm_observe': 0,
                   'm_race': ' ',
                   'm_result': 2,
               'm_teamId': 0,
               'm_toon': {'m_id': ,
                          'm_programId': 'Hero',
                          'm_realm': 1,
                          'm_region': 2},
               'm_workingSetSlotId': 1},
              {'m_color': {'m_a': 255, 'm_b': 255, 'm_g': 92, 'm_r': 36},
               'm_control': 2,
               'm_handicap': 100,
               'm_hero': 'Kerrigan',
               'm_name': 'Breez',
               'm_observe': 0,
               'm_race': ' ',
               'm_result': 2,
               'm_teamId': 0,
               'm_toon': {'m_id': ,
                          'm_programId': 'Hero',
                          'm_realm': 1,
                          'm_region': 2},
               'm_workingSetSlotId': 2},
              {'m_color': {'m_a': 255, 'm_b': 0, 'm_g': 0, 'm_r': 255},
               'm_control': 2,
               'm_handicap': 100,
               'm_hero': 'L\xc3\xa9oric',
               'm_name': 'Mopsio',
               'm_observe': 0,
               'm_race': ' ',
               'm_result': 1,
               'm_teamId': 1,
               'm_toon': {'m_id': ,
                          'm_programId': 'Hero',
                          'm_realm': 1,
                          'm_region': 2},
               'm_workingSetSlotId': 3},
              {'m_color': {'m_a': 255, 'm_b': 255, 'm_g': 92, 'm_r': 36},
               'm_control': 2,
               'm_handicap': 100,
               'm_hero': 'Tyrande',
               'm_name': 'Blekitny',
               'm_observe': 0,
               'm_race': ' ',
               'm_result': 2,
               'm_teamId': 0,
               'm_toon': {'m_id': ,
                          'm_programId': 'Hero',
                          'm_realm': 1,
                          'm_region': 2},
               'm_workingSetSlotId': 4},
              {'m_color': {'m_a': 255, 'm_b': 0, 'm_g': 0, 'm_r': 255},
               'm_control': 2,
               'm_handicap': 100,
               'm_hero': 'Uther',
               'm_name': 'Kr\xc3\xb3Lu',
               'm_observe': 0,
               'm_race': ' ',
               'm_result': 1,
               'm_teamId': 1,
               'm_toon': {'m_id': ,
                          'm_programId': 'Hero',
                          'm_realm': 1,
                          'm_region': 2},
               'm_workingSetSlotId': 5},
              {'m_color': {'m_a': 255, 'm_b': 255, 'm_g': 92, 'm_r': 36},
               'm_control': 2,
               'm_handicap': 100,
               'm_hero': 'Falstad',
               'm_name': 'Atheroangel',
               'm_observe': 0,
               'm_race': ' ',
               'm_result': 2,
               'm_teamId': 0,
               'm_toon': {'m_id': ,
                          'm_programId': 'Hero',
                          'm_realm': 1,
                          'm_region': 2},
               'm_workingSetSlotId': 6},
              {'m_color': {'m_a': 255, 'm_b': 0, 'm_g': 0, 'm_r': 255},
               'm_control': 2,
               'm_handicap': 100,
               'm_hero': 'Muradin',
               'm_name': 'TankFtw',
               'm_observe': 0,
               'm_race': ' ',
               'm_result': 1,
               'm_teamId': 1,
               'm_toon': {'m_id': ,
                          'm_programId': 'Hero',
                          'm_realm': 1,
                          'm_region': 2},
               'm_workingSetSlotId': 7},
              {'m_color': {'m_a': 255, 'm_b': 0, 'm_g': 0, 'm_r': 255},
               'm_control': 2,
               'm_handicap': 100,
               'm_hero': 'Valla',
               'm_name': 'ZDOON',
               'm_observe': 0,
               'm_race': ' ',
               'm_result': 1,
               'm_teamId': 1,
               'm_toon': {'m_id': ,
                          'm_programId': 'Hero',
                          'm_realm': 1,
                          'm_region': 2},
               'm_workingSetSlotId': 8},
              {'m_color': {'m_a': 255, 'm_b': 255, 'm_g': 92, 'm_r': 36},
               'm_control': 2,
               'm_handicap': 100,
               'm_hero': 'Balafr\xc3\xa9',
               'm_name': 'scHwimpi',
               'm_observe': 0,
               'm_race': ' ',
               'm_result': 2,
               'm_teamId': 0,
               'm_toon': {'m_id': ,
                          'm_programId': 'Hero',
                          'm_realm': 1,
                          'm_region': 2},
               'm_workingSetSlotId': 9},
              {'m_color': {'m_a': 255, 'm_b': 0, 'm_g': 0, 'm_r': 255},
               'm_control': 2,
               'm_handicap': 100,
               'm_hero': 'Thrall',
               'm_name': 'Remmerballer',
               'm_observe': 0,
               'm_race': ' ',
               'm_result': 1,
               'm_teamId': 1,
               'm_toon': {'m_id': ,
                          'm_programId': 'Hero',
                          'm_realm': 1,
                          'm_region': 2},
               'm_workingSetSlotId': 10}],
 'm_restartAsTransitionMap': False,
 'm_thumbnail': {'m_file': 'ReplaysPreviewImage.tga'},
 'm_timeLocalOffset': 36000000000,
 'm_timeUTC': 130983747603980954,
 'm_title': 'Comt\xc3\xa9 du Dragon'}

1 个答案:

答案 0 :(得分:0)

JSONLint说这不是有效的JSON代码

JSON不允许用单引号分隔字符串',你必须使用双引号“

您可以尝试替换

$output = str_replace('"', '\\"', $output); //this is to escape existing double-quotes
    //which would otherwise break the JSON-string
$output = str_replace("'", '"', $output);

但正确的解决方案是修复库以生成有效的JSON

注意:如果您的数据中有任何转义单引号,我的替换修补程序将无效。