JSON.parse()不包括数组中的点和小数

时间:2018-05-10 00:05:04

标签: javascript jquery ajax

当我尝试在全局数组中推送之前使用解析时,小数分数被删除我正在搜索并且他们告诉我如果使用.eval可能会解决但是它不起作用我已经尝试过.replace和.substring但没有解决...我需要我的json的那些字段没有双引号,以便我可以计算列的值和我使用的库不计入引号内的值,例如:

JSON.parse()totalPurchased之后的220.00列中的数字:totalPurchased220可以告诉我为什么会这样?

            // Native Array
            var receivedDataOne = [];

            // Group Received JSON By Total Of Purchased
            for (var i = 0; i < allResponseTwo.length; i++) {
                // Group Received JSON By Total Of Purchased
                var totalOfPurchased = allResponseTwo[i].purchase_history;
                for (var j = 0; j < totalOfPurchased.length; j++) {
                    // Declare Variables Containing Extend Details
                    var purchasedProductNested = totalOfPurchased[j].purchasedProduct;
                    var quantityOfPurchasedNested = totalOfPurchased[j].quantityPurchased;
                    var totalOfPurchasedNested = totalOfPurchased[j].totalOfPurchased;
                    var totalOfDiscountsPurchasedNested = totalOfPurchased[j].discountsToConsider;

                    // Format The Money So That It Is Possible To Count
                    totalOfPurchasedNested = totalOfPurchasedNested.replace(/\./g, "").replace(",", ".");
                    totalOfDiscountsPurchasedNested = totalOfDiscountsPurchasedNested.replace(/\./g, "").replace(",", ".");

                    // Final JSON Array Containing Extend Details
                    var allResponseTwoWithExtendDetails = {
                        product: purchasedProductNested,
                        quantity: quantityOfPurchasedNested,
                        totalPurchased: JSON.parse(totalOfPurchasedNested),
                        totalDiscounts: totalOfDiscountsPurchasedNested
                    };

                    // Push Group With Received JSON In Native Array
                    receivedDataOne.push(allResponseTwoWithExtendDetails);
                }
            }

My project in JSFiddle

感谢您的帮助:D

0 个答案:

没有答案