I need to convert a string of xml data or json data into a tabular form in mysql.
the json_extract function can only deal with a single json data, but not the json array. The data taken by the ExtractValue function are spliced together. I don"t know how to separate them. Is there any other way? please consult the gods
data sample:
[{"fCategoryId": "796", "fCondition": "0.8"}, {"fCategoryId": "730", "fCondition": "0.05"}, {"fCategoryId": "731", "fCondition": "0.05"}]
select CONVERT(json_extract("{"fCategoryId":"796","fCondition":"0.8"}","$.fCondition"),DECIMAL(5,2)) AS fcid;
if you enter an json array, there is no output
< jrt >
<item>
<fCategoryId>1006</fCategoryId>
<fCondition>0.40</fCondition>
</item>
<item>
<fCategoryId>1007</fCategoryId>
<fCondition>0.30</fCondition>
</item>
<item>
<fCategoryId>1008</fCategoryId>
<fCondition>0.30</fCondition>
</item>
< / jrt >
SET @xmlstring = "<jrt><item><fCategoryId>1006</fCategoryId><fCondition>0.40</fCondition></item><item><fCategoryId>1007</fCategoryId><fCondition>0.30</fCondition></item><item><fCategoryId>1008</fCategoryId><fCondition>0.30</fCondition></item></jrt>"
;
SELECT ExtractValue(@xmlstring, "/jrt/item/fCategoryId") as fCategoryId,ExtractValue(@xmlstring, "/jrt/item/fCondition") as fCondition;
the data obtained is in the form of
fCategoryId | fCondition
1006 1007 1008 | 0.400.300.30