首页 > 解决方案 > 问题嵌套 JSON 无法在数据表中显示值

问题描述

来自服务器的响应:

["{\"CLIENT\":[{\"tranche\":\"1-4\",\"prix\":\"65.96\",\"currency\":\"E\"}],\"DISTRIBUTEUR\":[{\"tranche\":\"1-4\",\"prix\":52.77,\"currency\":\"E\"}],\"FILLIALE\":[{\"tranche\":\"1-4\",\"prix\":46.17,\"currency\":\"E\"}],\"NULL\":[{\"error\":\"Compte inconnu\"}],\"NCN_23\":[{\"prix\":46.17,\"currency\":0}],\"NNA_USA\":[{\"prix\":46.17,\"currency\":0}]}","{\"CLIENT\":[{\"tranche\":\"5-9\",\"prix\":\"57.38\",\"currency\":\"E\"}],\"DISTRIBUTEUR\":[{\"tranche\":\"5-9\",\"prix\":45.9,\"currency\":\"E\"}],\"FILLIALE\":[{\"tranche\":\"5-9\",\"prix\":40.17,\"currency\":\"E\"}],\"NULL\":[{\"error\":\"Compte inconnu\"}],\"NCN_23\":[{\"prix\":40.17,\"currency\":0}],\"NNA_USA\":[{\"prix\":40.17,\"currency\":0}]}","{\"CLIENT\":[{\"tranche\":\"10-24\",\"prix\":\"53.61\",\"currency\":\"E\"}],\"DISTRIBUTEUR\":[{\"tranche\":\"10-24\",\"prix\":42.89,\"currency\":\"E\"}],\"FILLIALE\":[{\"tranche\":\"10-24\",\"prix\":37.53,\"currency\":\"E\"}],\"NULL\":[{\"error\":\"Compte inconnu\"}],\"NCN_23\":[{\"prix\":37.53,\"currency\":0}],\"NNA_USA\":[{\"prix\":37.53,\"currency\":0}]}","{\"CLIENT\":[{\"tranche\":\"25-49\",\"prix\":\"46.49\",\"currency\":\"E\"}],\"DISTRIBUTEUR\":[{\"tranche\":\"25-49\",\"prix\":37.19,\"currency\":\"E\"}],\"FILLIALE\":[{\"tranche\":\"25-49\",\"prix\":32.54,\"currency\":\"E\"}],\"NULL\":[{\"error\":\"Compte inconnu\"}],\"NCN_23\":[{\"prix\":32.54,\"currency\":0}],\"NNA_USA\":[{\"prix\":32.54,\"currency\":0}]}","{\"CLIENT\":[{\"tranche\":\"50-99\",\"prix\":\"45.55\",\"currency\":\"E\"}],\"DISTRIBUTEUR\":[{\"tranche\":\"50-99\",\"prix\":36.44,\"currency\":\"E\"}],\"FILLIALE\":[{\"tranche\":\"50-99\",\"prix\":31.89,\"currency\":\"E\"}],\"NULL\":[{\"error\":\"Compte inconnu\"}],\"NCN_23\":[{\"prix\":31.89,\"currency\":0}],\"NNA_USA\":[{\"prix\":31.89,\"currency\":0}]}","{\"CLIENT\":[{\"tranche\":\"100-249\",\"prix\":\"37.75\",\"currency\":\"E\"}],\"DISTRIBUTEUR\":[{\"tranche\":\"100-249\",\"prix\":30.2,\"currency\":\"E\"}],\"FILLIALE\":[{\"tranche\":\"100-249\",\"prix\":26.43,\"currency\":\"E\"}],\"NULL\":[{\"error\":\"Compte inconnu\"}],\"NCN_23\":[{\"prix\":26.43,\"currency\":0}],\"NNA_USA\":[{\"prix\":26.43,\"currency\":0}]}","{\"CLIENT\":[{\"tranche\":\"250-499\",\"prix\":\"33.14\",\"currency\":\"E\"}],\"DISTRIBUTEUR\":[{\"tranche\":\"250-499\",\"prix\":26.51,\"currency\":\"E\"}],\"FILLIALE\":[{\"tranche\":\"250-499\",\"prix\":23.2,\"currency\":\"E\"}],\"NULL\":[{\"error\":\"Compte inconnu\"}],\"NCN_23\":[{\"prix\":23.2,\"currency\":0}],\"NNA_USA\":[{\"prix\":23.2,\"currency\":0}]}","{\"CLIENT\":[{\"tranche\":\"500-999\",\"prix\":\"29.31\",\"currency\":\"E\"}],\"DISTRIBUTEUR\":[{\"tranche\":\"500-999\",\"prix\":23.45,\"currency\":\"E\"}],\"FILLIALE\":[{\"tranche\":\"500-999\",\"prix\":20.52,\"currency\":\"E\"}],\"NULL\":[{\"error\":\"Compte inconnu\"}],\"NCN_23\":[{\"prix\":20.52,\"currency\":0}],\"NNA_USA\":[{\"prix\":20.52,\"currency\":0}]}","{\"CLIENT\":[{\"tranche\":\"1000+\",\"prix\":\"27.95\",\"currency\":\"E\"}],\"DISTRIBUTEUR\":[{\"tranche\":\"1000+\",\"prix\":22.36,\"currency\":\"E\"}],\"FILLIALE\":[{\"tranche\":\"1000+\",\"prix\":19.57,\"currency\":\"E\"}],\"NULL\":[{\"error\":\"Compte inconnu\"}],\"NCN_23\":[{\"prix\":19.57,\"currency\":0}],\"NNA_USA\":[{\"prix\":19.57,\"currency\":0}]}"]

     var jsonData=JSON.parse(response.getReturnValue());
                        console.log(jsonData); 

  component.set('v.mycolumns',[{label: 'S No', fieldName: 'SNO', type: 'text'},
                     {label: 'Client Type', fieldName: 'Client', type: 'text'},
                     {label: 'Slab', fieldName: 'tranche', type: 'text'},
                     {label: 'Price', fieldName: 'prix', type: 'text'},
                   {label: 'Currency', fieldName: 'currency', type: 'text'},

                         ])

                       var rows=[];              
                            for (var key in jsonData){
                             var curName = key;
                             var value = jsonData[key];
                             var test = jsonData[key[value]];
                       rows.push({SNO : curName,
                       Client:jsonData[curName]+"",
                       currency:(jsonData[curName[test]].currency)+"",  
                       prix:(jsonData[curName[test]].prix)+"",
                       tranche:(jsonData[curName[test]].tranche)+""});   
                       }
                        component.set('v.mydata',rows);  
                    }
              });
                // enqueue the server side action  
                $A.enqueueAction(action);

我想在我的数据表中显示这个项目

我将所有值都设为“未定义”

有人可以帮我解决这个错误吗?

标签: javascriptjqueryangularjsjson

解决方案


试试这个:

    var myMessage=["{\"CLIENT\":[{\"tranche\":\"1-4\",\"prix\":\"65.96\",\"currency\":\"E\"}],\"DISTRIBUTEUR\":[{\"tranche\":\"1-4\",\"prix\":52.77,\"currency\":\"E\"}],\"FILLIALE\":[{\"tranche\":\"1-4\",\"prix\":46.17,\"currency\":\"E\"}],\"NULL\":[{\"error\":\"Compte inconnu\"}],\"NCN_23\":[{\"prix\":46.17,\"currency\":0}],\"NNA_USA\":[{\"prix\":46.17,\"currency\":0}]}","{\"CLIENT\":[{\"tranche\":\"5-9\",\"prix\":\"57.38\",\"currency\":\"E\"}],\"DISTRIBUTEUR\":[{\"tranche\":\"5-9\",\"prix\":45.9,\"currency\":\"E\"}],\"FILLIALE\":[{\"tranche\":\"5-9\",\"prix\":40.17,\"currency\":\"E\"}],\"NULL\":[{\"error\":\"Compte inconnu\"}],\"NCN_23\":[{\"prix\":40.17,\"currency\":0}],\"NNA_USA\":[{\"prix\":40.17,\"currency\":0}]}","{\"CLIENT\":[{\"tranche\":\"10-24\",\"prix\":\"53.61\",\"currency\":\"E\"}],\"DISTRIBUTEUR\":[{\"tranche\":\"10-24\",\"prix\":42.89,\"currency\":\"E\"}],\"FILLIALE\":[{\"tranche\":\"10-24\",\"prix\":37.53,\"currency\":\"E\"}],\"NULL\":[{\"error\":\"Compte inconnu\"}],\"NCN_23\":[{\"prix\":37.53,\"currency\":0}],\"NNA_USA\":[{\"prix\":37.53,\"currency\":0}]}","{\"CLIENT\":[{\"tranche\":\"25-49\",\"prix\":\"46.49\",\"currency\":\"E\"}],\"DISTRIBUTEUR\":[{\"tranche\":\"25-49\",\"prix\":37.19,\"currency\":\"E\"}],\"FILLIALE\":[{\"tranche\":\"25-49\",\"prix\":32.54,\"currency\":\"E\"}],\"NULL\":[{\"error\":\"Compte inconnu\"}],\"NCN_23\":[{\"prix\":32.54,\"currency\":0}],\"NNA_USA\":[{\"prix\":32.54,\"currency\":0}]}","{\"CLIENT\":[{\"tranche\":\"50-99\",\"prix\":\"45.55\",\"currency\":\"E\"}],\"DISTRIBUTEUR\":[{\"tranche\":\"50-99\",\"prix\":36.44,\"currency\":\"E\"}],\"FILLIALE\":[{\"tranche\":\"50-99\",\"prix\":31.89,\"currency\":\"E\"}],\"NULL\":[{\"error\":\"Compte inconnu\"}],\"NCN_23\":[{\"prix\":31.89,\"currency\":0}],\"NNA_USA\":[{\"prix\":31.89,\"currency\":0}]}","{\"CLIENT\":[{\"tranche\":\"100-249\",\"prix\":\"37.75\",\"currency\":\"E\"}],\"DISTRIBUTEUR\":[{\"tranche\":\"100-249\",\"prix\":30.2,\"currency\":\"E\"}],\"FILLIALE\":[{\"tranche\":\"100-249\",\"prix\":26.43,\"currency\":\"E\"}],\"NULL\":[{\"error\":\"Compte inconnu\"}],\"NCN_23\":[{\"prix\":26.43,\"currency\":0}],\"NNA_USA\":[{\"prix\":26.43,\"currency\":0}]}","{\"CLIENT\":[{\"tranche\":\"250-499\",\"prix\":\"33.14\",\"currency\":\"E\"}],\"DISTRIBUTEUR\":[{\"tranche\":\"250-499\",\"prix\":26.51,\"currency\":\"E\"}],\"FILLIALE\":[{\"tranche\":\"250-499\",\"prix\":23.2,\"currency\":\"E\"}],\"NULL\":[{\"error\":\"Compte inconnu\"}],\"NCN_23\":[{\"prix\":23.2,\"currency\":0}],\"NNA_USA\":[{\"prix\":23.2,\"currency\":0}]}","{\"CLIENT\":[{\"tranche\":\"500-999\",\"prix\":\"29.31\",\"currency\":\"E\"}],\"DISTRIBUTEUR\":[{\"tranche\":\"500-999\",\"prix\":23.45,\"currency\":\"E\"}],\"FILLIALE\":[{\"tranche\":\"500-999\",\"prix\":20.52,\"currency\":\"E\"}],\"NULL\":[{\"error\":\"Compte inconnu\"}],\"NCN_23\":[{\"prix\":20.52,\"currency\":0}],\"NNA_USA\":[{\"prix\":20.52,\"currency\":0}]}","{\"CLIENT\":[{\"tranche\":\"1000+\",\"prix\":\"27.95\",\"currency\":\"E\"}],\"DISTRIBUTEUR\":[{\"tranche\":\"1000+\",\"prix\":22.36,\"currency\":\"E\"}],\"FILLIALE\":[{\"tranche\":\"1000+\",\"prix\":19.57,\"currency\":\"E\"}],\"NULL\":[{\"error\":\"Compte inconnu\"}],\"NCN_23\":[{\"prix\":19.57,\"currency\":0}],\"NNA_USA\":[{\"prix\":19.57,\"currency\":0}]}"];

    var jsonData = JSON.parse("["+myMessage+"]");
    
    console.log(jsonData);


推荐阅读