SyntaxError: Unexpected token T in JSON at position

SyntaxError: Unexpected token T in JSON at position

当我尝试解析以下 JSON 内容时出现此异常

SyntaxError: Unexpected token T in JSON at position 236
    at JSON.parse (<anonymous>)
    at AppComponent.populatePivotGrid (app.component.js:18)
    at _View_AppComponent0._handle_click_3_0 (/AppModule/AppComponent/component.ngfactory.js:76)
    at eval (core.umd.js:9437)
    at eval (platform-browser.umd.js:1525)
    at eval (platform-browser.umd.js:1638)
    at ZoneDelegate.invoke (zone.js:232)
    at Object.onInvoke (core.umd.js:6206)
    at ZoneDelegate.invoke (zone.js:231)
    at Zone.runGuarded (zone.js:128)

JSon内容:

var temp = '{"columns":"","measures":"[Measures].[Sold_Dollars],[Measures].[Sold_Units]","rows":"[Item_Id].[Item_Id],[Item_Desc].[Item_Desc]","metadata":{"cube":{"dimensions":[{"hierarchies":[{"levels":[{"memberProvider":"function (item) { return \"Total Rtlr Name\"; }","caption":"Total Rtlr Name","name":"TotalRtlr_Name"},{"memberProvider":"function (item) { return item.Rtlr_Name; }","caption":"Rtlr Name","name":"Rtlr_Name"}],"caption":"Rtlr Name","name":"Rtlr_Name"}],"caption":"Rtlr Name","name":"Rtlr_Name"},{"hierarchies":[{"levels":[{"memberProvider":"function (item) { return \"Total Item Id\"; }","caption":"Total Item Id","name":"TotalItem_Id"},{"memberProvider":"function (item) { return item.Item_Id; }","caption":"Item Id","name":"Item_Id"}],"caption":"Item Id","name":"Item_Id"}],"caption":"Item Id","name":"Item_Id"},{"hierarchies":[{"levels":[{"memberProvider":"function (item) { return \"Total Item Desc\"; }","caption":"Total Item Desc","name":"TotalItem_Desc"},{"memberProvider":"function (item) { return item.Item_Desc; }","caption":"Item Desc","name":"Item_Desc"}],"caption":"Item Desc","name":"Item_Desc"}],"caption":"Item Desc","name":"Item_Desc"}],"measuresDimension":{"measures":[{"aggregator":"function(items, cellMetadata) { var sum = 0; $.each(items, function(index, item) { sum += item.Sold_Dollars; } );   $.ig.regional.defaults.currencyMaxDecimals = 0;   $.ig.regional.defaults.currencyMinDecimals = 0;   return $.ig.formatter(parseFloat(sum), \"number\", \"#########0\"); }","caption":"Sold Dollars","name":"Sold_Dollars"},{"aggregator":"function(items, cellMetadata) { var sum = 0; $.each(items, function(index, item) { sum += item.Sold_Units; } );   $.ig.regional.defaults.currencyMaxDecimals = 0;   $.ig.regional.defaults.currencyMinDecimals = 0;   return $.ig.formatter(parseFloat(sum), \"number\", \"#########0\"); }","caption":"Sold Units","name":"Sold_Units"},{"aggregator":"function(items, cellMetadata) { var sum = 0; $.each(items, function(index, item) { sum += item.Rtlr_Price; } );   $.ig.regional.defaults.currencyMaxDecimals = 0;   $.ig.regional.defaults.currencyMinDecimals = 0;   return $.ig.formatter(parseFloat(sum), \"number\", \"#########0\"); }","caption":"Rtlr Price","name":"Rtlr_Price"},{"aggregator":"function(items, cellMetadata) { var sum = 0; $.each(items, function(index, item) { sum += item.Rtlr_Cost; } );   $.ig.regional.defaults.currencyMaxDecimals = 0;   $.ig.regional.defaults.currencyMinDecimals = 0;   return $.ig.formatter(parseFloat(sum), \"number\", \"#########0\"); }","caption":"Rtlr Cost","name":"Rtlr_Cost"}],"name":"Measures"},"caption":"Report substr Sample Recreated Diff World","name":"Report substr Sample Recreated Diff World"}}}';
      
   var test = JSON.parse(temp);//it breaks here with the above mentioned exception/error

此 JSON 内容有什么问题?

您需要使用双 \ 来转义引号。

所以代替:... return \"Total Rtlr Name\"; ...

写成:... return \\"Total Rtlr Name\\"; ...

希望对您有所帮助。