dtamho6404
2016-05-10 18:52
浏览 238
已采纳

获取JSON的第一个条目

I have this JSON in a URL:

{"success":true,"rgInventory":{"6073259621":{"id":"6073259621","classid":"1660549198","instanceid":"188530139","amount":"1","pos":1}}}

I need obtain the first entry after rgInventory. The problem is the problem is that suppose that I don't know that there are "6073259621". How I can obtain it without know what there?

I try this but don't work:

$obj = json_decode(file_get_contents($url), true);
$obj2 = json_decode(json_encode($obj['rgInventory']), true);
$obj3 = json_decode(json_encode($obj2), true); 
echo $obj3;

图片转代码服务由CSDN问答提供 功能建议

我在URL中有这个JSON:

  {“ 成功 “:真实的,” rgInventory “:{” 6073259621 “:{” ID “:” 6073259621" , “CLASSID”: “1660549198”, “实例id”: “188530139”, “量”: “1”, “POS”  :1}}} 
   
 
 

我需要在 rgInventory 之后获取第一个条目。 问题是问题是假设我不知道有“6073259621”。 我怎么能在不知道是什么的情况下获得呢?

我试试这个但不起作用:

  $ obj = json_decode(file_get_contents  ($ url),true); 
 $ obj2 = json_decode(json_encode($ obj ['rgInventory']),true); 
 $ obj3 = json_decode(json_encode($ obj2),true);  
echo $ obj3; 
   
 
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

3条回答 默认 最新

相关推荐 更多相似问题