开发者

how to read 3 json responses like one

开发者 https://www.devze.com 2023-03-14 12:28 出处:网络
I have 3 functions that invoke a json response function one gives: { \"IT_INFO\": { \"CARNET\": \"999250 \",

I have 3 functions that invoke a json response

function one gives:

{
    "IT_INFO": {
        "CARNET": "999250 ",
        "CEDULA": "000013724224",
        "NOMBRE": "pedro ",
        "SEGNOMBRE": "salomon ",
        "APELLIDO": "Perez ",
        "SEGAPELLIDO": "Perza ",
        "EMAIL": "mail@mailexample.com ",
        "IAP": "0.00",
        "IAA": "0.00"
    }
}

second function :

{
    "HISTORICOP": [
        {
            "MATERIA": "PROCESOS DEL LENGUAJE ",
            "NOTA": "7 ",
            "ANIO": "2000",
            "PERIODO": "001",
            "ENEMENOSUNO": "Ordinaria. Estado por defecto "
        }
    ]
}

third function:

{
    "HORARIO": [
        {
            "CODIGO": "BERSP01 ",
            "MATERIA": " COMPUTADOR ",
            "AULA": "A1-102 ",
            "PROFESOR": "Quintero Moros, Nelson ",
            "HORARIO": "TU WE FR 08:00-10:00 "
        }
    ]
}

How should it come out so the function JSON开发者_运维百科.parse(str) will read it?

str = [func1,func2,func3] ??

or

str = [[func1],[func2],[func3]]?

or??? any ideas???


I assume you parse the JSON in JavaScript.

Normally you should not build JSON "manually", but in this case it does not seem to be too bad:

var objs = JSON.parse('[' + [func1(), func2(), func3()].join(',') + ']');

This creates a JSON array with the three objects returned by the functions.

Alternatively you can parse the responses individually:

var objs = [func1(), func2(), func3()];
for(var i = objs.length; i--; ) {
   objs[i] = JSON.parse(objs[i]);
}

Of course you have to do things differently if the functions don't return the JSON but make some Ajax request...

0

精彩评论

暂无评论...
验证码 换一张
取 消