PHP复杂字符串解析,可以使用JSON吗? [英] PHP Complex String Parse, JSON'able?

查看:238
本文介绍了PHP复杂字符串解析,可以使用JSON吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有以下PHP字符串:

So I have the following PHP string:

$output = {"playerId":1178,"percentChange":0.1,"averageDraftPosition":260,"percentOwned":0.1,"mostRecentNews":{"news":"Accardo was called up from Columbus on Monday, the Indians' official Twitter feed reports.","spin":"He'll replace Dan Wheeler on the active roster after carrying a 2.76 ERA over 13 appearances with the Clippers to start the season.","date":"Mon May 14"},"fullName":"Jeremy Accardo"}

我需要的是:印第安人的官方Twitter提要报道称,周一,阿卡多从哥伦布被召唤出来."和他将在快船开始13场比赛后以2.76 ERA替换现役阵容中的Dan Wheeler,以开始新赛季."作为子字符串.但是我似乎无法找出最好,最优雅的方式来做到这一点.我尝试对字符串进行JSON_decode,但未返回任何内容.有任何想法吗? (我正在使用PHP)

What I need is: "Accardo was called up from Columbus on Monday, the Indians' official Twitter feed reports." and "He'll replace Dan Wheeler on the active roster after carrying a 2.76 ERA over 13 appearances with the Clippers to start the season." as substrings. But I can't seem to figure out the best and most elegant way to do that. I tried to JSON_decode the string but I get nothing returned. Any ideas? (I am using PHP)

推荐答案

您有几个未转义的字符串,这导致了错误.一种简单的格式可以节省您的时间.

you have few unescaped string, that is causing the error. a simple formatting could have saved you the time.

$output = '{
    "playerId":1178,
    "percentChange":0.1,
    "averageDraftPosition":260,
    "percentOwned":0.1,
    "mostRecentNews": {
        "news":"Accardo was called up from Columbus on Monday, the Indians official Twitter feed reports",
        "spin":"Hell replace Dan Wheeler on the active roster after carrying a 2.76 ERA over 13 appearances with the Clippers to start the season.",
        "date":"Mon May 14"
    },
    "fullName":"Jeremy Accardo"
}';
$json = json_decode($output);

这篇关于PHP复杂字符串解析,可以使用JSON吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆