我有一个从csv文件生成的json对象:
{"FID":["FID"],"the_geom":["the_geom"],"X":["X"],"Y":["Y"],"ROW":["ROW"],"COL":["COL"],"EMH":["EMH"],"B":["B_SURF","B_SUB1","B_SUB2"],"BP_CA":["BP_CA_SUR","BP_CA_SUB1","BP_CA_SUB2"],"BP_K":["BP_K_SURF","BP_K_SUB1","BP_K_SUB2"],"BP_MG"["BP_MG_SUR","BP_MG_SUB1","BP_MG_SUB2"],"BP_NA":["BP_NA_SUR","BP_NA_SUB1","BP_NA_SUB2"],"CA"["CA_SURF","CA_SUB1","CA_SUB2"],"CAMG":["CAMG_SURF","CAMG_SUB1","CAMG_SUB2"],"CEC"["CEC_SURF","CEC_SUB1","CEC_SUB2"],"CLAY":["CLAY_SURF","CLAY_SUB1","CLAY_SUB2"],"CU"["CU_SURF","CU_SUB1","CU_SUB2"],"DPRR_SUMM":["DPRR_SUMM"],"DRAIN_SUMM"["DRAIN_SUMM"],"FE":["FE_SURF","FE_SUB1","FE_SUB2"],"K"["K_SURF","K_SUB1","K_SUB2"],"KMG":["KMG_SURF","KMG_SUB1","KMG_SUB2"],"MG"["MG_SURF","MG_SUB1","MG_SUB2"],"MN":["MN_SURF","MN_SUB1","MN_SUB2"],"NA":["NA_SURF","NA_SUB1","NA_SUB2"],"OM":["OM_SURF","OM_SUB1","OM_SUB2"],"P"["P_SURF","P_SUB1","P_SUB2"],"PAVL"["PAVL_SURF","PAVL_SUB1","PAVL_SUB2"],"PAW24_SUMM":["PAW24_SUMM"],"PAW30_SUMM"["PAW30_SUMM"],"PAW36_SUMM":["PAW36_SUMM"],"PAW42_SUMM":["PAW42_SUMM"],"PAW48_SUMM":["PAW48_SUMM"],"PH":["PH_SURF","PH_SUB1","PH_SUB2"],"RZFC_SUMM":["RZFC_SUMM"],"RZKUSAT_SU"["RZKUSAT_SU"],"RZPAW_SUMM":["RZPAW_SUMM"],"RZPWP_SUMM"["RZPWP_SUMM"],"RZSAT_SUMM":["RZSAT_SUMM"],"S":["S_SURF","S_SUB1","S_SUB2"],"SAND":["SAND_SURF","SAND_SUB1","SAND_SUB2"],"TEX"["TEX_SURF","TEX_SUB1","TEX_SUB2"],"THICK"["THICK_SURF","THICK_SUB1","THICK_SUB2"],"TIP":["TIP_SURF","TIP_SUB1","TIP_SUB2"],"ZN":["ZN_SURF","ZN_SUB1","ZN_SUB2"],"EMV"["EMV"],"ASP":["ASP"],"DEM":["DEM"],"SLOPE\r":["SLOPE\r"]}
最后,坡度对象的名称中有一个回车符(它是从csv转换中带来的)
我需要从对象中删除该回车符,因为它会破坏一些解析对象的其他脚本。
我尝试通过以下方式对其进行测试:
console.log("Without carrage return: " + JSON.stringify(jsonObject).replace(/[\n\r]/g, ''));
但是当我打印它时,它仍然包含回车符。
我可能在这里做了一些愚蠢的事情,只是太累了,没有注意到它。
非常感谢任何帮助!
replace(/\\r/g, '')
。 - sigod\r
。 - MinusFourJSON.stringify()
会将控制字符转义成其转义序列表示形式。 如果输入包含字符串\r
,则JSON将包含\\r
,而.replace(/[\\r\\n]/g, '')
将无法匹配它。 - cg909