我正在尝试获取所有内容,但JSON中的某些字符串未显示在我的脚本中。有人会在我的代码中发现错误吗?
$url = "http://natomilcorp.com/api/get-users";
$jsonString = file_get_contents($url);
$obj = json_decode($jsonString, true);
$sptr = 0;
$x = 0;
$itemID = 1;
while (is_numeric($itemID)) {
if ($x == 1) {
$findUserID = 0;
$findUserIDEnd = '":';
$sptr = strpos($jsonString, $findUserID, $sptr + 1) + 2;
$eptr = strpos($jsonString, $findUserIDEnd, $sptr + 1);
$length = $eptr - $sptr;
$itemID = substr($jsonString, $sptr, $length);
} else {
$findUserID = 'datejoined":"';
$findUserIDEnd = '"';
$sptr = strpos($jsonString, $findUserID, $sptr + 1) + 27;
$eptr = strpos($jsonString, $findUserIDEnd, $sptr + 1);
$length = $eptr - $sptr;
$itemID = substr($jsonString, $sptr, $length);
}
$findUserName = '"username":"';
$findLastSeen = '"lastseen":"';
$findDateJoined = '"datejoined":"';
$findEnd = '"';
$sptr = strpos($jsonString, $findUserName, $sptr + 1) + 12;
$eptr = strpos($jsonString, $findEnd, $sptr + 1);
$length = $eptr - $sptr;
$itemName = substr($jsonString, $sptr, $length); // Name
$sptr = strpos($jsonString, $findLastSeen, $sptr + 1) + 12;
$eptr = strpos($jsonString, $findEnd, $sptr + 1);
$length = $eptr - $sptr;
$itemLastSeen = substr($jsonString, $sptr, $length); // Name
$sptr = strpos($jsonString, $findDateJoined, $sptr + 1) + 14;
$eptr = strpos($jsonString, $findEnd, $sptr + 1);
$length = $eptr - $sptr;
$itemDateJoined = substr($jsonString, $sptr, $length); // Name
$LastSeen = date("F j, Y, g:i a", $itemLastSeen);
$DateJoined = date("F j, Y, g:i a", $itemDateJoined);
if (is_numeric($itemID)) {
$x +=1;
echo $x . ". INSERT INTO `player`(`id`,`name`,`enjinId`) VALUE (" ."'$itemID','$itemName', '$itemID'" . ")<br>";
}
}
应该有至少80名成员,但我只看到46
谢谢你的帮助!我真的很感激!
答案 0 :(得分:1)
你有多个错误,我不知道你的目的是什么 回答以下问题并帮助我帮助你:)
为什么你不使用$ obj?
$content = file_get_contents('http://natomilcorp.com/api/get-users');
$array = json_decode($content,TRUE);
var_dump($array);
echo count($array);
9430088 =>
array (size=7)
'username' => string '[PVT.]Flynn, C.' (length=15)
'forum_post_count' => string '1' (length=1)
'forum_votes' => string '0' (length=1)
'forum_up_votes' => string '0' (length=1)
'forum_down_votes' => string '0' (length=1)
'lastseen' => string '1394941661' (length=10)
'datejoined' => string '1394839236' (length=10)
9442152 =>
array (size=7)
'username' => string 'Rct. Evanicki, K.' (length=17)
'forum_post_count' => string '0' (length=1)
'forum_votes' => string '0' (length=1)
'forum_up_votes' => string '0' (length=1)
'forum_down_votes' => string '0' (length=1)
'lastseen' => string '1394926383' (length=10)
'datejoined' => string '1394910499' (length=10)
物品数量:90
为什么要增加ID?如果id定义PK(主键)和AI(自动增量) 你不需要手动增加
$ queries。=&#34; INSERT INTO player
(name
,enjinId
)VALUE(&#39;&#34;。$ itemName。&#34;& #39;,&#39;&#34;。$ itemID。&#34;&#39;)&#34;;
为什么要打印插件而不是用PHP代码插入它们?
为什么Id和itemID插入的值相同?