Javascript 如何从json检索特定数据,json值来自url

Javascript 如何从json检索特定数据,json值来自url,javascript,php,jquery,arrays,json,Javascript,Php,Jquery,Arrays,Json,为了从JSON中检索数据,我尝试了其他关于同一问题的问题。但它们都不适合我,因为我的JSON数据与其他数据不同 也许我的问题听起来和其他问题一样,但我已经试过了 [ { "bHeader":{ "ei":"NSE", "seg":"I" }, "cNetChangeIndicator":"\u0000", "fClosingIndex":10558.5, "fHighIndexVal

为了从JSON中检索数据,我尝试了其他关于同一问题的问题。但它们都不适合我,因为我的JSON数据与其他数据不同

也许我的问题听起来和其他问题一样,但我已经试过了

[  
   {  
      "bHeader":{  
         "ei":"NSE",
         "seg":"I"
      },
      "cNetChangeIndicator":"\u0000",
      "fClosingIndex":10558.5,
      "fHighIndexValue":10532.0,
      "fIndexValue":10469.0,
      "fLowIndexValue":10438.5,
      "fOpeningIndex":10499.5,
      "fPercentChange":-0.85,
      "sIndexName":"962450",
      "fChange":-89.5,
      "iIdxId":311
   }
]
请帮我找出这些值

fIndexValue
fChange
fPercentChange.

您尝试过JSON.parse(请求)吗?您将能够作为对象访问

请尝试以下操作:

$data = '[  
   {  
      "bHeader":{  
         "ei":"NSE",
         "seg":"I"
      },
      "cNetChangeIndicator":"\u0000",
      "fClosingIndex":10558.5,
      "fHighIndexValue":10532.0,
      "fIndexValue":10469.0,
      "fLowIndexValue":10438.5,
      "fOpeningIndex":10499.5,
      "fPercentChange":-0.85,
      "sIndexName":"962450",
      "fChange":-89.5,
      "iIdxId":311
   }
]';

$data = json_decode($data);
foreach ($data as $d){
   echo  $d->fIndexValue;
   echo  $d->fChange;
   echo  $d->fPercentChange;
}
var数据=[{“bHeader”:{“ei”:“NSE”,“seg”:“I”},“CNETCHANGEINDER”:“\u0000”,“fClosingIndex”:10558.5,“fHighIndexValue”:10532.0,“FindxValue”:10469.0,“fLowIndexValue”:10438.5,“FopengingingIndex”:10499.5,“fPercentChange”:-0.85,“sIndexName”:“962450”,“fChange”:-89.5,“iIdxId”:311});
data.forEach(功能(项){
log('fIndexValue:'+item.fIndexValue);
console.log('fChange:'+item.fChange);
log('fPercentChange:'+item.fPercentChange);

});已更新

您可以使用
json\u解码(json\u字符串,true)
php函数,如下所示

$str = '[{"bHeader":{"ei":"NSE","seg":"I"},"cNetChangeIndicator":"\u0000","fClosingIndex":10558.5,"fHighIndexValue":10532.0,"fIndexValue":10469.0,"fLowIndexValue":10438.5,"fOpeningIndex":10499.5,"fPercentChange":-0.85,"sIndexName":"962450","fChange":-89.5,"iIdxId":311}]';

$arr = json_decode($str, true);

print_r($arr);

echo $arr[0]['fIndexValue'];
echo $arr[0]['fChange'];
echo $arr[0]['fPercentChange'];
每30秒刷新一次页面。在下面编写代码

// write the function
function refresh($time)
{
    $current_url = $_SERVER[ 'REQUEST_URI' ];
    return header( "Refresh: " . $time . "; URL=$current_url" );
}

// call the function in the appropriate place
refresh(30);
// this refreshes page after 4 seconds

您可以执行以下操作:

$data = '[  
   {  
      "bHeader":{  
         "ei":"NSE",
         "seg":"I"
      },
      "cNetChangeIndicator":"\u0000",
      "fClosingIndex":10558.5,
      "fHighIndexValue":10532.0,
      "fIndexValue":10469.0,
      "fLowIndexValue":10438.5,
      "fOpeningIndex":10499.5,
      "fPercentChange":-0.85,
      "sIndexName":"962450",
      "fChange":-89.5,
      "iIdxId":311
   }
]';

$data = json_decode($data);
foreach ($data as $d){
   echo  $d->fIndexValue;
   echo  $d->fChange;
   echo  $d->fPercentChange;
}

您的json是二维的,因此您应该尝试以下操作

data[0]['fHighIndexValue']

坐立不安


预期的输出是什么?您的尝试面临什么问题?问题是我没有获得fIndexValue、fChange、fPercentChange的值。我尝试了此链接“我的json格式不同,你也可以分享一下你的尝试吗?嗨,Pablo Fuentes,你能解释一下吗,因为我不知道json,这不会打印任何东西,echo$arr[0]['fIndexValue'];echo$arr[0]['fChange'];echo$arr[0]['fPercentChange'];另外,$str值是动态的,来自url,所以我需要在30秒后刷新该url。我使用了Curl,但它没有完成任务。我的电子邮件id是-anindya12。it@gmail.comI'我得到的是总数组,而不是这些值分别回显$arr[0]['fIndexValue'];echo$arr[0]['fChange'];echo$arr[0]['fPercentChange'];在本印刷品中($arr);数组您可以在json中传递的数组中看到整个值。可以使用此数组获取值