奇怪的数据类型转换问题 [英] strange data type Conversion problem
问题描述
嗨!
使用JSON提取器读取JSON文件并以CSV格式导出.我以为,除非强制转换,否则所有东西都是字符串!但是
Reading a JSON file and exporting as a CSV using the JSON extractor. I thought every thing would be a string unless cast! But
为什么要输入:
{"ID":226552,"DetailCost":-0.000066}
{"ID":226552,"DetailCost":-0.312519}
{"ID":226552,"DetailCost":-0.000066}
{"ID":226552,"DetailCost":-0.312519}
创建输出:
@InBillLocationInvoiceProduct =
EXTRACT jsonString string
FROM @inputBillLocationInvoiceProduct
USING Extractors.Text(delimiter:'\b', quoting:false);
@jsonifyBillLocationInvoiceProduct =
SELECT Microsoft.Analytics.Samples.Formats.Json.JsonFunctions.JsonTuple(jsonString) AS recBillLocationInvoiceProduct
FROM @InBillLocationInvoiceProduct;
@InBillLocationInvoiceProductJSON =
SELECT
recBillLocationInvoiceProduct["ID"] AS BillLocationInvoiceProductId,
recBillLocationInvoiceProduct["DetailCost"] AS DetailCost
FROM @jsonifyBillLocationInvoiceProduct;
@InBillLocationInvoiceProduct =
SELECT (int) Int32.Parse(BillLocationInvoiceProductId) AS BillLocationInvoiceProductId,
DetailCost
FROM @InBillLocationInvoiceProductJSON;
OUTPUT @InBillLocationInvoiceProduct TO @outBillLocationInvoiceProduct ORDER BY BillLocationInvoiceProductId USING Outputters.Csv(outputHeader: true);
推荐答案
由于您使用的是JSON解析器,因此它将转换为float,因为该值不在双引号内.您可以尝试在输入文件中将值用双引号引起来,或使用转换器将float转换为字符串,如下所示:
Since you are using a JSON parser, it converts into float because the value is not within double quotes. you can try wrapping the value in double quotes in your input file or use a converter to convert from float to string like below:
Convert.ToString("DetailCost") AS DetailCost;
string.Format("{0:N3}", DetailCost) AS DetailCost; //upto 3 decimal places
这篇关于奇怪的数据类型转换问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!