PHP无法解析响应对象

时间:2012-08-13 11:48:28

标签: php arrays parsing

我正在拨打OCRWebservice.com&收到这样的回复

object(stdClass)#5 (1) {
["OCRWSResponse"]=>
object(stdClass)#6 (2) {
    ["ocrText"]=>
        object(stdClass)#7 (1) {
            ["ArrayOfString"]=>
                object(stdClass)#8 (1) {
                    ["string"]=>
                            string(109) "......,......,- PHYSICIANS HAVE BIGGER STAKE IN PATIENT, TOTAL CARE UNDER MEDICARE ACOs AROUNDTHEINDUSTRY "
                }
        }
    ["ocrWSWords"]=>
        object(stdClass)#9 (0) {
        }
}
}

object(stdClass)#10 (1) {
["OCRWSResponse"]=>
    object(stdClass)#11 (2) {
        ["ocrText"]=>
            object(stdClass)#12 (1) {
                ["ArrayOfString"]=>
                    object(stdClass)#13 (1) {
                        ["string"]=>
                        string(21) "AROUNDTHEINDUSTRY 10 "
                    }
            }
        ["ocrWSWords"]=>
            object(stdClass)#14 (0) {
        }
}
}

我无法将其解析为$ response-> OCRWSResponse-> ocrText。我需要读取ocrText中的字符串值。

似乎返回了多个OCRWSResponse。我需要通过它们循环播放得到所有的ocrText。有人可以帮忙吗?

1 个答案:

答案 0 :(得分:1)

试试这个:

<?php
// $response is the response
echo $response->OCRWSResponse->ocrText->ArrayOfString->string;
?>