JavaScript
x
13
13
1
var action=component.get("c.callCostCatalog");
2
3
action.setParams({ wrapperStructure:JSON.stringify(component.get("v.listStructurePV")),
4
consumoTotal:component.get("v.consumTotal"),
5
Rate:'Vacia',
6
orderItemID: component.get("v.recordId"),
7
PMPInicial:component.get("v.precioInicial")})
8
9
action.setCallback(this,function(response){
10
//var listWrapper = JSON.parse(response.getReturnValue()); -> log shows [object object]
11
var listWrapper = JSON.parse(JSON.stringify(response.getReturnValue()));
12
//listWrapper.usedBand returns undefined
13
})
callCostCatalog
is an Apex method which returns the string:
JavaScript
1
2
1
{"usedBand":0.0,"PMPObjetivo":0.0,"PMPNegotiated":0.028533,"PMPInit":0.028533,"negotiationBands":null,"Negotiation":0.0,"negBandCI":null,"minBandSD":null,"minBandRZ":null,"minBandRT":null,"minBandD":null,"minBand":null,"maxBandSD":null,"maxBandRZ":null,"maxBandRT":null,"maxBandD":null,"maxBand":null,"lNegotiatedPrices":[80.97],"lInitPrices":[0.028533],"lImplicitPrice":[],"lConsums":[]}
2
Advertisement
Answer
Your JSON.parse
is right, and your console.log
is right, and your JSON is valid.
However, you have erroneously called JSON.stringify
, which is like the reverse of parse
, taking a JavaScript object and producing a string of JSON. You don’t want that; you already have a string of JSON. Simply remove it.