Javascript 问题:嵌套JSON无法在datatable中显示值

Javascript 问题:嵌套JSON无法在datatable中显示值,javascript,jquery,angularjs,json,Javascript,Jquery,Angularjs,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

来自服务器的响应:

["{\"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);
我想在我的数据表中显示此项

我得到的所有值都是“未定义的”

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

你能试试吗

JSON.parse(response.getReturnValue()[0])
我认为这应该适用于上述JSON响应。JSON是有效的

试试这个:

“1-4\”,“prix\”:::“65.96\”,“货币\”:“65.96\”,“货币\”:“E\””,“货币\”:“E\”””””,,“分发者\””,,“分发者\””,,“分发者\”,,“客户”以下以下以下以下以下简称“客户”的消息=,,,“客户”们们们们,”,”,”,”,”,”,”上述上述上述上述网页网页网页网页网页网页网页网页网页网页网页名名名名名名名名名名名名名名名,”,”,”,”。“。“。“。“。“。“。“客户”的消息,”,”,”,”以下以下以下网页名名名名名名名名名名名名名名名名名名名名名名名名,”,”,”,”在以下以下以下以下以下以下以下以下以下以下以下以下的“客户:::,,,,,,,,,,,,,,,,,,,,,,,,“Pri23“:[{\'prix\':46.17,\'currency\':0}],\'NNA\u USA\':[{”46.17岁的普里克斯:46.17岁,一个“货币”的“货币”点:0.00},”,”,”,”一个“客户”客户端:““5-9”款,”5-9-9\”,“普里克斯”点:57.38岁,”46.17,“货币”点:46.17,“货币”点:46.17,“货币”点,”货币:46.17.17,“货币:货币”点:46.17.17.17,“,,,,,,,,,,,,,,,,,“客户”客户:““客户:““““““““客户”们们”们们”们们们们::::,,,,,,,,,,,,,,,,,,,“““““““部分部分”们们们们们们们们们们们们们们们们们,”,”,”,”一些“可能会不会不会不会不会不会不会不会不会不会不会不会不会不会不会不会不会不会不会不会不会不会不会不会““Compte Inconu\”,“NCN\U 23\”:[{“prix\”:40.17,““currency\”:0}],“NNA\U USA”\“,,““客户”们:“,“客户”们:“,,,,,,““客户”们:“,,,“普里克斯”普里克斯“:“53.61\”,,“普里克斯”普里克斯“:“53.61\”:40.17,”40.17,40.17,”40.17,40.17,10.17,,,“货币”40.17,“,,,,,,,,,,,,““客户”客户”客户:““,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,“货币”“error\”:“Compte inconnu\”],“NCN\u 23\”:[{\“prix\”:37.53,\“currency\”:0}],,““客户”客户:““客户”客户:“,,“客户”客户:“,,““客户”客户:”,,““客户”客户:”,““客户”客户:“,,“美国网络美国”的一个美国网络,”美国网络“美国网络公司”的一部分:“,,“美国网络公司”美国网络公司的一个“美国网络公司”美国的一部分:“,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,“货币:““货币:”::::::::,,,,,,,,,,,,,,,,,,“货币:“::::::::,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,“NULL\”:[{\“error\”:“Compte inconnu\”}],“NCN\u 23\”:[{\“prix\”:32.54\“货币”0.54,““货币”0.10,”客户:“,,““客户”客户端:“,,““客户”客户端:“,,,““客户”客户:“,,,,“货币”货币:0.货币:0.0 0.00以下以下以下几点,”货币:0.0.00以下几点,”货币:美国的一个“美国国家”和“美国的一个“美国国家”的网络:“:::,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,:\“E\”}],\“NULL\”:[{\“error\”:\“Compte inconnu\”}],“NCN\u 23\”:[{”31.89,“货币”普利克斯:31.89,““货币”普利克斯:31.89,““货币”普利克斯:31.89,“货币:0.0}”,““客户”客户:31.89,“““客户”客户:31.89,,“货币”普利克斯:31.89,,,,“货币”普利克斯:37.75“,,,“37.75.75\,,,,“货币”货币:“:“E美国”美国一家美国”美国。以下::::::,,,,,,,,,,,,,,,,“分配者:,,,,,,,,,,“货币:,,,,,,,,,,,,,,,,,,,,,,“货币:,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,X\“:26.43,\'currency\':\'E\'}],\'NULL\':[{\'error\':\'Compte inconnu\'}]“NCN-23”以下几点:26.43,“货币”0.0},,“美国国家网络”美国,”美国国家网络公司:26.43,“货币”26.43,“货币”0.23,,,“网络网络网络23”23.23以下以下几点:“,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,\“:\“250-499\”,\“prix\”:23.2,\“currency\”:\“E\”,\“NULL\”:[{“error\”:\”,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,“普里克斯:,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,美国美国的美国美国政府:,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,[{“分期付款”:“500-999\”,“prix\”:20.52,,“货币”:“E\”,”“NCN”23“:”:[“普里克斯”20.52,货币“货币”0.52,”货币“货币”0.00,,美国纽约州国家一名美国国家一名美国国家一名美国国家一名。以下以下:::“:[“错误”错误:“:,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,“}],“FILLIALE\”:[{“tranche\”:“1000+”,“prix\”:19.57,\”货币\“:\“E\”}],“NULL\”:[{“error\”:“Compte inconu\”}],“NCN\u 23\”:[{“prix\”:19.57,“currency\”:0}],“NNA\u USA\”:[{“prix\”:19.57,\“currency\”:0}]; var jsonData=JSON.parse(“[”+myMessage+“]”);
console.log(jsonData)什么是
getReturnValue
返回的?这是第1行吗?@82Tuskers在我的第一行中提到了json上面的那一行是的..但这是一个数组,在元素[0]处包含一个字符串。它只给出一个结果“[”,作为上面代码的输出好的,明白了…然后你想做
json.parse(response.getReturnValue())[0]
并将其分配给
jsonData
也不起作用。它只返回1组数据。我有8组数据可能是服务器响应问题。因为在粘贴的JSON中,我只看到以下键的一个数组元素:
[“CLIENT”、“distributer”、“FILLIALE”、“NULL”、“NCN_23”、“NNA_USA”]