gpt4 book ai didi

java - 使用正则表达式将字符串数据的键和值格式化为 json 键值对

转载 作者:行者123 更新时间:2023-12-01 10:31:14 25 4
gpt4 key购买 nike

这是我们必须用双引号“Key”:“value”括起来以格式化的示例数据:

{Data:{Management:[{individual:{individual_Suffx:,individual_FName:XYZ,individual_LName:ABC,individual_Emplyee_Title:BOARD SECRETARY&PRESIDENT/CEO,individual_Directng_MName:MNO,individual_DOB:1960-05-21},individual_Tin:{},individual_NPI_Id:{},individual_OrgIndvdl:[{Ownrshp_MngngCntrl_EfctvDt:2009-11-30,Ownrshp_MngngCntrl_RoleCd:W},{Ownrshp_MngngCntrl_EfctvDt:2009-11-30,Ownrshp_MngngCntrl_RoleCd:10},{Ownrshp_MngngCntrl_EfctvDt:2009-11-30,Ownrshp_MngngCntrl_RoleCd:15}],Mngng_Mdcr:{}},{Mngng_Indvdl:{Mngng_Indvdl_FName:TIMOTHY,Mngng_Indvdl_LName:TOOLEY,Mngng_Indvdl_MName:C,Mngng_Indvdl_DOB:1958-07-02},Mngng_Tin:{},Mngng_NPI_Id:{},Mngng_OrgIndvdl:{OwnrshpIntrst_MngngCntrl_EfctvDt:2014-05-01,Ownrshp_MngngCntrl_RoleCd:W},Mngng_Mdcr:{}}}}

最佳答案

不确定这是否涵盖所有极端情况,但此正则表达式应该适用于您的示例:

String json = ...
json = json.replaceAll("[^{}\\[\\]:,]+", "\"$0\"");

关于java - 使用正则表达式将字符串数据的键和值格式化为 json 键值对,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35071617/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com