使用php以特定格式显示数据

时间:2016-03-24 20:26:27

标签: php

我有以下输出。我想用php阅读它。 请让我知道如何做到这一点

 .POST,
    "https://www.googleapis.com/upload/youtube/v3/videos?part=snippet",
    headers: headers,
    multipartFormData: { multipartFormData in
        multipartFormData.appendBodyPart(data:"{'snippet':{'title' : 'TITLE_TEXT', 'description': 'DESCRIPTION_TEXT'}}".dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)!, name :"snippet", mimeType: "application/json")
        multipartFormData.appendBodyPart(data: videodata, name: "video", fileName: "video.mp4", mimeType: "application/octet-stream")
},

1 个答案:

答案 0 :(得分:1)

嗯,除了起始?(和结尾);之外,你看起来像JSON。删除后,您应该能够使用json_decode将字符串解码为PHP stdClass对象,并以这种方式访问​​它的值。

粗略地完成,你可以尝试类似的东西:

$result = '    ?({"ip":"104.112.115.28","country_code":"US","country_name":"United States","region_code":"CA","region_name":"California","city":"Houston","zip_code":"90013","time_zone":"America/Los_Angeles","latitude":34.0453,"longitude":-118.2413,"metro_code":803});';

//remove the bad stuff on the start and end, which assumes these strings don't exist elsewhere in the result, which is a pretty big assumption
$string = str_replace('?({', '{', str_replace('});', '}', trim($result));

$data = json_decode($string);

echo $data->ip;

同样,这是一个粗略的答案,并做出了一个很大的假设,但在大多数情况下它可能会起作用;肯定是你给出的例子。