我从cleeng API得到了这个回应;如何将此响应转换为JSON

时间:2016-09-17 08:08:13

标签: php json

Cleeng_Entity_Collection Object
(
    [entityType:protected] => Cleeng_Entity_SubscriptionOffer
    [items:protected] => Array
        (
            [0] => Cleeng_Entity_SubscriptionOffer Object
                (
                    [id:protected] => S955494970_US
                    [publisherEmail:protected] => vidya+mtc@ooyala.com
                    [url:protected] => 
                    [title:protected] => Annual subscription
                    [description:protected] => 
                    [period:protected] => year
                    [price:protected] => 49.99
                    [applicableTaxRate:protected] => 0
                    [currency:protected] => USD
                    [accessToTags:protected] => Array
                        (
                            [0] => d962607d3d4c4e3c98a343c7bcb64027
                        )

                    [active:protected] => 1
                    [createdAt:protected] => 1473681112
                    [updatedAt:protected] => 1473858745
                    [geoRestrictionEnabled:protected] => 
                    [geoRestrictionType:protected] => 
                    [geoRestrictionCountries:protected] => Array
                        (
                        )

                    [pending:protected] => 
                    [country] => US
                    [socialCommissionRate] => 0
                    [averageRating] => 4
                    [contentType] => 
                    [freePeriods] => 0
                    [freeDays] => 0
                    [expiresAt] => 
                )
        )
    [totalItemCount:protected] => 5
    [pending:protected] => 
)

1 个答案:

答案 0 :(得分:0)

您只需将Collection转换为Regular Array,然后将json_encode()结果转换为:

<?php

    $entityCollection = "???"; // THIS IS THE DATA FROM Cleeng_Entity_Collection Object
    $entityArray      = $entityCollection->toArray();
    $entityJSON       = json_encode($entityArray);