我是使用curl的新手,我不知道如何解析这个链接到JSON:
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'https://doodle-manga-
scraper.p.mashape.com/mangafox.me/manga/naruto/1'
));
我有这个PHP脚本:
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib
matplotlib.style.use('ggplot')
from mpl_toolkits.mplot3d import Axes3D
from mpldatacursor import datacursor
AccX = pd.read_csv('Data_Retrieval_April_05_2017.csv')
AccX.columns = ['Tag', 'Timestamp', 'X']
AccX = AccX[AccX['Tag'].str.contains("ACC856:AccelerationX")]
del AccX['Tag']
print(AccX.head())
AccY = pd.read_csv('Data_Retrieval_April_05_2017.csv')
AccY.columns = ['Tag', 'Timestamp', 'Y']
AccY = AccY[AccY['Tag'].str.contains("ACC856:AccelerationY")]
del AccY['Tag']
print(AccY.head())
AccZ = pd.read_csv('Data_Retrieval_April_05_2017.csv')
AccZ.columns = ['Tag', 'Timestamp', 'Z']
AccZ = AccZ[AccZ['Tag'].str.contains("ACC856:AccelerationZ")]
del AccZ['Tag']
print(AccZ.head())
Accel = AccX.merge(AccY,on='Timestamp').merge(AccZ,on='Timestamp')
Accel = Accel.set_index(['Timestamp'])
print(Accel.head())
Accel['X'] = Accel.X.astype(float)
Accel['Y'] = Accel.Y.astype(float)
Accel['Z'] = Accel.Z.astype(float)
print(Accel.head())
print(Accel.dtypes)
accelscat = plt.figure().gca(projection='3d')
accelscat.scatter(Accel['X'],Accel['Y'],Accel['Z'], c='darkblue', alpha=0.5)
accelscat.set_xlabel('X')
accelscat.set_ylabel('Y')
accelscat.set_zlabel('Z')
plt.show()
我从未使用过curl。如何使用PHP从上面的命令解析数据?
答案 0 :(得分:0)
我们正在讨论解析响应,是吗?你需要安装python,但这对我有用:
| python -m json.tool
将其放在陈述的最后。所以你的看起来像是:
curl --get --include 'https://doodle-manga-
scraper.p.mashape.com/mangafox.me/manga/naruto/1' \
-H 'X-Mashape-Key: LhdkCyyF6Tmsh3BXTnN79quTbg08p1j2B20jsn89wOXridOzNe' \
-H 'Accept: text/plain' | python -m json.tool
答案 1 :(得分:0)
$post = array('X-Mashape-Key' =>'LhdkCyyF6Tmsh3BXTnN79quTbg08p1j2B20jsn89wOXridOzNe' , 'Accept' => 'text/plain');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://doodle-manga-scraper.p.mashape.com/mangafox.me/manga/naruto/1');
curl_setopt($ch, CURLOPT_POST, True);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, True);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$result = curl_exec($ch);
$jsonresult = json_decode($result);
这应该是