从JSON编码的数组字符串中获取值

从JSON编码的数组字符串中获取值

本文介绍了从JSON编码的数组字符串中获取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

文件fetchvalues.php中的.php代码如下所示:

My .php code in a file "fetchvalues.php" looks like this:

echo json_encode(array($PostedDate.Places.$Company.$Designation.$ProjectDetails.$DesiredCandidate.$HRName.$HRContact.$Email));

此文件由另一个文件调用,调用函数如下所示:

This file is called by another file and the calling function looks like:

$(document).ready(function(){
    $("#Edit").click(function(){
    $.getJSON("fetchvalues.php?UpdateRecordID=" + $.cookie('UpdateRecordID'),
    function(data){
    // Data retrieved in concatenated form. So we will break it and store values in array.
    var concatenatedvalues = new Array();
    concatenatedValues = data;
    alert(concatenatedValues);
    });
});
});

数据正在成功返回,但我没有关注如何通过javascript获取每个数组元素。上述代码需要进行哪些修改?

The data is being returned successfully, but I am not following how get each array element through javascript. What modifications are needed in the above code?

推荐答案

更新我只是重新阅读您的问题,它看起来像就像你故意连接价值观一样。由于您使用 json_encode ,将值作为数组发送会更好,只需在JavaScript中访问它。

Update I just reread your question and it looks like you intentionally concatenated the values. Since you are using json_encode it would be much better to send the values as an array, and simply access it in JavaScript.

echo json_encode(array($PostedDate, $Places, $Company, $Designation, $ProjectDetails, $DesiredCandidate, $HRName, $HRContact, $Email));

然后在JavaScript中,他们会像这样访问:

Then in JavaScript they would be accessed like this:

alert(data[1]); // Would alert the value of $Places

这篇关于从JSON编码的数组字符串中获取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 23:12