访问以字符串形式传递的json数据

时间:2021-12-01 14:57:58

I am passing data from php in json format, how do I access it?

我以json格式从php传递数据,我该如何访问它?

This is the result:

这是结果:

{"solctype":"Long Term Agreement","checkbox":"1","prnumber":"356363563"}

I have tried

我努力了

$.post("getgrid?id="+id,
{
},
function(data, status){
    console.log(data.solctype);

});

This always returns undefined

这总是返回undefined

1 个解决方案

#1


1  

You need to parse the string data and convert it to a JavaScript object.

您需要解析字符串数据并将其转换为JavaScript对象。

Use something like this:

使用这样的东西:

    var stringData = {"solctype":"Long Term Agreement","checkbox":"1","prnumber":"356363563"};
    var parsedData = JSON.parse(stringData);
    console.log(parsedData.solctype)

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse

#1


1  

You need to parse the string data and convert it to a JavaScript object.

您需要解析字符串数据并将其转换为JavaScript对象。

Use something like this:

使用这样的东西:

    var stringData = {"solctype":"Long Term Agreement","checkbox":"1","prnumber":"356363563"};
    var parsedData = JSON.parse(stringData);
    console.log(parsedData.solctype)

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse