我有这个XML响应:
<AuthorisationResult xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://webservice.redletterdays.co.uk/">
<RequestSuccessful>true</RequestSuccessful>
<ErrorMessage/>
<Token>3d3d4a94-87fe-414c-ae0a-fd0e0c4c0060</Token>
</AuthorisationResult>
这就是我写作时所得到的:
return $res;
如何访问令牌?
我试试:
return $res->Token;
以及
return $res->children();
但是这段代码给我的错误......
那么,我如何能够以XML格式访问Token或如何转换为JSON并轻松访问令牌,如$ res-&gt; Token ......
答案 0 :(得分:1)
试试这个:
import cv2
import os
import numpy as np
def findCenter(img):
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
th, threshed = cv2.threshold(gray, 127, 255, cv2.THRESH_BINARY_INV | cv2.THRESH_OTSU)
_, cnts, hierarchy = cv2.findContours(threshed, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
M = cv2.moments(cnts[0])
cX = int(M["m10"] / M["m00"])
cY = int(M["m01"] / M["m00"])
return (cX, cY)
img1 = cv2.imread("Path of the image you want to copy")
img2 = cv2.imread("Path of the image you want to use like a backgroud")
pt1 = findCenter(img1)
pt2 = findCenter(img2)
## (2) Calc offset
dx = (pt1[0] - pt2[0])
dy = (pt1[1] - pt2[1])
h, w = img2.shape[:2]
dst = img1.copy()
dst[dy:dy + h, dx:dx + w] = img2
cv2.imwrite(path + roi, dst)
答案 1 :(得分:0)
我用以下方法解决了我的问题:
$res = json_encode(simplexml_load_string($res->getBody()));
$res = json_decode($res);
$token = $res->Token;