在ASP.NET

时间:2017-06-01 08:36:19

标签: jquery asp.net json

是否可以使用JQuery或Javascript将以下JSON拼接或拆分为两个变量? 我是从webmethod获取它们,我需要将它们分开, 我想做点什么, var x = JSON 1 var Y = JSON 2 有可能吗?

{
"PtRegData": [{
    "RecID": 1277,
    "filenum": 15090248,
    "name": "Ahmad Morsi abdul fattah Abu Maizerasdasd",
    "msgcode": "info",
    "msgtitle": "Succsessful SQL Transaction",
    "msg": "Record has been updated succsessfully",
    "PartnerData": null
}],
"PartnerData": [{
        "RecID": 2383,
        "PrtStatus": 0,
        "ptfilenum": 15090248,
        "prfilenum": 13090701
    },
    {
        "RecID": 3387,
        "PrtStatus": 1,
        "ptfilenum": 15090248,
        "prfilenum": 15120996
    },
    {
        "RecID": 3388,
        "PrtStatus": 1,
        "ptfilenum": 15090248,
        "prfilenum": 170227111
    },
    {
        "RecID": 3416,
        "PrtStatus": 1,
        "ptfilenum": 15090248,
        "prfilenum": 11021602
    }
]}

JSON 1

{
"PtRegData": [{
    "RecID": 1277,
    "filenum": 15090248,
    "name": "Ahmad Morsi abdul fattah Abu Maizerasdasd",
    "msgcode": "info",
    "msgtitle": "Succsessful SQL Transaction",
    "msg": "Record has been updated succsessfully",
    "PartnerData": null
}]}

JSON 2

{
"PartnerData": [{
        "RecID": 2383,
        "PrtStatus": 0,
        "ptfilenum": 15090248,
        "prfilenum": 13090701
    },
    {
        "RecID": 3387,
        "PrtStatus": 1,
        "ptfilenum": 15090248,
        "prfilenum": 15120996
    },
    {
        "RecID": 3388,
        "PrtStatus": 1,
        "ptfilenum": 15090248,
        "prfilenum": 170227111
    },
    {
        "RecID": 3416,
        "PrtStatus": 1,
        "ptfilenum": 15090248,
        "prfilenum": 11021602
    }
]}



var json = {
"PtRegData": [{
    "RecID": 1277,
    "filenum": 15090248,
    "name": "Ahmad Morsi abdul fattah Abu Maizerasdasd",
    "msgcode": "info",
    "msgtitle": "Succsessful SQL Transaction",
    "msg": "Record has been updated succsessfully",
    "PartnerData": null
}],
"PartnerData": [{
        "RecID": 2383,
        "PrtStatus": 0,
        "ptfilenum": 15090248,
        "prfilenum": 13090701
    },
    {
        "RecID": 3387,
        "PrtStatus": 1,
        "ptfilenum": 15090248,
        "prfilenum": 15120996
    },
    {
        "RecID": 3388,
        "PrtStatus": 1,
        "ptfilenum": 15090248,
        "prfilenum": 170227111
    },
    {
        "RecID": 3416,
        "PrtStatus": 1,
        "ptfilenum": 15090248,
        "prfilenum": 11021602
    }
]}


var json1 = json.PtRegData;
var json2 = json.PartnerData;
console.log(json1)
console.log(json2)




1 个答案:

答案 0 :(得分:2)

你应该做

var json = {
"PtRegData": [{
    "RecID": 1277,
    "filenum": 15090248,
    "name": "Ahmad Morsi abdul fattah Abu Maizerasdasd",
    "msgcode": "info",
    "msgtitle": "Succsessful SQL Transaction",
    "msg": "Record has been updated succsessfully",
    "PartnerData": null
}],
"PartnerData": [{
        "RecID": 2383,
        "PrtStatus": 0,
        "ptfilenum": 15090248,
        "prfilenum": 13090701
    },
    {
        "RecID": 3387,
        "PrtStatus": 1,
        "ptfilenum": 15090248,
        "prfilenum": 15120996
    },
    {
        "RecID": 3388,
        "PrtStatus": 1,
        "ptfilenum": 15090248,
        "prfilenum": 170227111
    },
    {
        "RecID": 3416,
        "PrtStatus": 1,
        "ptfilenum": 15090248,
        "prfilenum": 11021602
    }
]}


var json1 = json.PtRegData;
var json2 = json.PartnerData;
console.log(json1)
console.log(json2)