首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从字符串对象中获取单独的对象

从字符串对象中获取单独的对象
EN

Stack Overflow用户
提问于 2017-03-14 20:30:08
回答 1查看 47关注 0票数 0

极客们,

我在java中有一个字符串,它的值如下

{“organizationName”:“备件-展厅销售,Uaq","organizationCode":"S05","retailPrice":"32","onHandQuantity":"0","index":1} {”organizationName“:”备件-展厅销售,HiQ Shj EMR","organizationCode":"S18","retailPrice":"32","onHandQuantity":"0","index":2} {“organizationName”:“备件-展厅销售,Dxb","organizationCode":"S16","retailPrice":"32","onHandQuantity":"0",“索引”:3}{“organizationName”:“备件陈列室销售,Dib","organizationCode":"S17","retailPrice":"32","onHandQuantity":"0",”索引“:4}{”organizationName“:”备件中心零件库“,"organizationCode":"S01","retailPrice":"32","onHandQuantity":"0",“索引”:5}{“organizationName”:“备件-展厅销售额,Awr","organizationCode":"S02","retailPrice":"32","onHandQuantity":"0",”索引“:6}{”organizationName“:”备件-展厅销售额,Shj","organizationCode":"S03","retailPrice":"32","onHandQuantity":"0",“索引”:7}{“organizationName”:“备件-展厅销售额,Ajm","organizationCode":"S04","retailPrice":"32","onHandQuantity":"0",“索引”:8}{“organizationName”:“备件-展厅销售额,Rak","organizationCode":"S06","retailPrice":"32","onHandQuantity":"0",”索引“:9}{”organizationName“:”备件-展厅销售额,Kal","organizationCode":"S07","retailPrice":"32","onHandQuantity":"0",“索引”:10}{“organizationName”:“备件-展厅销售,Fuj","organizationCode":"S08","retailPrice":"32","onHandQuantity":"0",”索引“:11}{”organizationName“:”备件-展厅销售,Kho","organizationCode":"S09","retailPrice":"32","onHandQuantity":"0",“索引”:12}{“organizationName”:“备件-展厅销售,Dhd","organizationCode":"S10","retailPrice":"32","onHandQuantity":"0",“索引”:13}{“organizationName”:“备件-展厅销售额,周六”,"organizationCode":"S11","retailPrice":"32","onHandQuantity":"0",“索引”:14}{“organizationName”:“备件-展厅销售额,Gus","organizationCode":"S12","retailPrice":"32","onHandQuantity":"0",“索引”:15}{“organizationName”:“备件-展厅销售,Szr","organizationCode":"S13","retailPrice":"32","onHandQuantity":"0",”索引“:16}{”organizationName“:”备件-展厅销售,HiQ MSF","organizationCode":"S19","retailPrice":"32","onHandQuantity":"0",“索引”:17}{“organizationName”:“备件-配件,PDI","organizationCode":"S21","retailPrice":"32","onHandQuantity":"0",“索引”:18}

如何为每个表示获取字符串对象,如{“organizationName”:“备件-附件,PDI","organizationCode":"S21","retailPrice":"32","onHandQuantity":"0","index":18}

所以基本上我会从上面得到18个String对象。

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-03-14 21:05:56

您可以尝试提取大括号之间的值,并将其格式化为json

代码语言:javascript
复制
    String s1 = ""; //your string
    Pattern pattern = Pattern.compile("\\{(.*?)}");
    Matcher matcher = pattern.matcher(s1);
    while (matcher.find()) {
        String.format("{%s}", matcher.group(1));
    }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42786072

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档