doutan4831 2014-04-29 15:59
浏览 21

肥皂如何只返回想要的结果?

Ok I'm calling an API using php soap that returns an array but i want to be able to specify what i want returned... Let me add some code see it it makes more sense: ok this calls the service returning my array:

 class MBClassService extends MBAPIService
    {   
        public function GetClassDescriptions(array $classDescriptionIDs, array $staffIDs, array $locationIDs, $startTime, $endTime, $PageSize = NULL, $CurrentPage = NULL, $XMLDetail = XMLDetail::Full, $Fields = NULL, SourceCredentials $credentials = null)
        {
            $additions = array();
            if (count($classDescriptionIDs) > 0){
                $additions['ClassDescriptionsIDs'] = $classDescriptionIDs;
                var_dump($additions['ClassDescriptionsIDs']);
            }
            if (count($staffIDs) > 0)
            {
                $additions['StaffIDs'] = $staffIDs;
            }
            if (count($locationIDs) > 0)
            {
                $additions['LocationIDs'] = $locationIDs;
            }
            if (isset($startDate))
            {
                $additions['StartClassDateTime'] = $startDate->format(DateTime::ATOM);
            }
            if (isset($endDate))
            {
                $additions['EndClassDateTime'] = $endDate->format(DateTime::ATOM);
            }

        $params = $this->GetMindbodyParams($additions, $this->GetCredentials($credentials), $XMLDetail, $PageSize, $CurrentPage, $Fields);

        try
        {
            $result = $this->client->GetClassDescriptions($params);
        }
        catch (SoapFault $fault)
        {
            DebugResponse($result);
            echo '</xmp><br/><br/> Error Message : <br/>', $fault->getMessage(); 
        }

        if ($this->debug)
        {
            DebugRequest($this->client);
            DebugResponse($this->client, $result);
        }

        return $result;
        }
}

I'm calling it like so:

$resultTest = $classService->GetClassDescriptions(array(502, 4, 5), array(), array(), null, null, 150, 0);

but no matter what i add to the first array in GetClassDescription it always returns all of the results... here is a sample of a var dump of $resultTest:

object(stdClass)#1023 (1) {
  ["GetClassDescriptionsResult"]=>
  object(stdClass)#1024 (7) {
    ["Status"]=>
    string(7) "Success"
    ["ErrorCode"]=>
    int(200)
    ["XMLDetail"]=>
    string(4) "Full"
    ["ResultCount"]=>
    int(132)
    ["CurrentPageIndex"]=>
    int(0)
    ["TotalPageCount"]=>
    int(1)
    ["ClassDescriptions"]=>
    object(stdClass)#1025 (1) {
      ["ClassDescription"]=>
      array(132) {
        [0]=>
        object(stdClass)#1026 (9) {
          ["Level"]=>
          object(stdClass)#1027 (2) {
            ["ID"]=>
            int(1)
            ["Name"]=>
            string(17) "Beginner"
          }
          ["ID"]=>
          int(1)
          ["Name"]=>
          string(23) "Salsa - Beginner/Novice"
          ["Description"]=>
          string(47) "Learn fun and easy basics for Salsa."
          ["Prereq"]=>
          string(37) "No prior lessons required."
          ["Notes"]=>
          string(0) ""
          ["LastUpdated"]=>
          string(22) "2012-11-30T18:57:29.91"
          ["Program"]=>
          object(stdClass)#1028 (3) {
            ["ID"]=>
            int(22)
            ["Name"]=>
            string(13) "Group Classes"
            ["ScheduleType"]=>
            string(6) "DropIn"
          }
          ["SessionType"]=>
          object(stdClass)#1029 (4) {
            ["DefaultTimeLength"]=>
            NULL
            ["ProgramID"]=>
            int(22)
            ["ID"]=>
            int(6)
            ["Name"]=>
            string(19) "Social Group Lesson"
          }
        }
        [1]=>
        object(stdClass)#1030 (9) {
          ["Level"]=>
          object(stdClass)#1031 (2) {
            ["ID"]=>
            int(1)
            ["Name"]=>
            string(17) "Absolute Beginner"
          }
          ["ID"]=>
          int(2)
          ["Name"]=>
          string(26) "Two Step - Beginner/Novice"
          ["Description"]=>
          string(51) "Learn fun & easy basics for Two Step"
          ["Prereq"]=>
          string(37) "No prior lessons required."
          ["Notes"]=>
          string(0) ""
          ["LastUpdated"]=>
          string(22) "2012-11-30T19:02:40.29"
          ["Program"]=>
          object(stdClass)#1032 (3) {
            ["ID"]=>
            int(22)
            ["Name"]=>
            string(13) "Group Classes"
            ["ScheduleType"]=>
            string(6) "DropIn"
          }
          ["SessionType"]=>
          object(stdClass)#1033 (4) {
            ["DefaultTimeLength"]=>
            NULL
            ["ProgramID"]=>
            int(22)
            ["ID"]=>
            int(6)
            ["Name"]=>
            string(19) "Social Group Lesson"
          }
          }
        }
      }
    }
  }
}

So how do i go about only returning the wanted results say:

["Level"]=> object(stdClass)#1031 (2) {["ID"]=>int(1) ["Name"]=> string(17) "Absolute Beginner"

only? I guess I could traverse the results after they have been retrived it just seemed like a wast to return what i don't need... Chris

  • 写回答

1条回答 默认 最新

  • douyun8674 2014-04-29 16:43
    关注

    I think it depends on the structure of API. Whatever the API's return is, that's what you have to deal with. You really have to parse.

    评论

报告相同问题?

悬赏问题

  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)