我有这样的Json内容
{"expand": "names,schema","startAt": 0,"maxResults": 50,"total": 1,"issues": [{"expand": "operations,versionedRepresentations,editmeta,changelog,renderedFields","id": "641955","self": "https://rb-tracker.bosch.com/tracker19/rest/api/latest/issue/641955","key": "EDATOOL-1411","fields": {"created": "2022-12-06T11:14:36.000+0100","customfield_10000": "{summaryBean=com.atlassian.jira.plugin.devstatus.rest.SummaryBean@24a1688f[summary={pullrequest=com.atlassian.jira.plugin.devstatus.rest.SummaryItemBean@23f2f23c[overall=PullRequestOverallBean{stateCount=0, state='OPEN', details=PullRequestOverallDetails{openCount=0, mergedCount=0, declinedCount=0}},byInstanceType={}], build=com.atlassian.jira.plugin.devstatus.rest.SummaryItemBean@321de5ab[overall=com.atlassian.jira.plugin.devstatus.summary.beans.BuildOverallBean@6ca82c6[failedBuildCount=0,successfulBuildCount=0,unknownBuildCount=0,count=0,lastUpdated=<null>,lastUpdatedTimestamp=<null>],byInstanceType={}], review=com.atlassian.jira.plugin.devstatus.rest.SummaryItemBean@5fc3e1e6[overall=com.atlassian.jira.plugin.devstatus.summary.beans.ReviewsOverallBean@7a2d42e3[stateCount=0,state=<null>,dueDate=<null>,overDue=false,count=0,lastUpdated=<null>,lastUpdatedTimestamp=<null>],byInstanceType={}], deployment-environment=com.atlassian.jira.plugin.devstatus.rest.SummaryItemBean@2740d0b0[overall=com.atlassian.jira.plugin.devstatus.summary.beans.DeploymentOverallBean@75ceaa2c[topEnvironments=[],showProjects=false,successfulCount=0,count=0,lastUpdated=<null>,lastUpdatedTimestamp=<null>],byInstanceType={}], repository=com.atlassian.jira.plugin.devstatus.rest.SummaryItemBean@35c2a9a2[overall=com.atlassian.jira.plugin.devstatus.summary.beans.CommitOverallBean@2568cfa3[count=0,lastUpdated=<null>,lastUpdatedTimestamp=<null>],byInstanceType={}], branch=com.atlassian.jira.plugin.devstatus.rest.SummaryItemBean@40c4eee[overall=com.atlassian.jira.plugin.devstatus.summary.beans.BranchOverallBean@4131b89[count=0,lastUpdated=<null>,lastUpdatedTimestamp=<null>],byInstanceType={}]},errors=[],configErrors=[]], devSummaryJson={\"cachedValue\":{\"errors\":[],\"configErrors\":[],\"summary\":{\"pullrequest\":{\"overall\":{\"count\":0,\"lastUpdated\":null,\"stateCount\":0,\"state\":\"OPEN\",\"details\":{\"openCount\":0,\"mergedCount\":0,\"declinedCount\":0,\"total\":0},\"open\":true},\"byInstanceType\":{}},\"build\":{\"overall\":{\"count\":0,\"lastUpdated\":null,\"failedBuildCount\":0,\"successfulBuildCount\":0,\"unknownBuildCount\":0},\"byInstanceType\":{}},\"review\":{\"overall\":{\"count\":0,\"lastUpdated\":null,\"stateCount\":0,\"state\":null,\"dueDate\":null,\"overDue\":false,\"completed\":false},\"byInstanceType\":{}},\"deployment-environment\":{\"overall\":{\"count\":0,\"lastUpdated\":null,\"topEnvironments\":[],\"showProjects\":false,\"successfulCount\":0},\"byInstanceType\":{}},\"repository\":{\"overall\":{\"count\":0,\"lastUpdated\":null},\"byInstanceType\":{}},\"branch\":{\"overall\":{\"count\":0,\"lastUpdated\":null},\"byInstanceType\":{}}}},\"isStale\":true}}"}}]}
因此,我想使用Regex来获取devSummaryJson={}块中的内容
我尝试使用devSummaryJson={.*,但它返回了一些额外字符
devSummaryJson={\"cachedValue\":{\"errors\":[],\"configErrors\":[],\"summary\":{\"pullrequest\":{\"overall\":{\"count\":1,\"lastUpdated\":\"2022-12-19T09:09:46.366+0100\",\"stateCount\":1,\"state\":\"MERGED\",\"details\":{\"openCount\":0,\"mergedCount\":1,\"declinedCount\":2,\"total\":3},\"open\":false},\"byInstanceType\":{\"stash\":{\"count\":1,\"name\":\"Bitbucket Server\"}}},\"build\":{\"overall\":{\"count\":0,\"lastUpdated\":null,\"failedBuildCount\":0,\"successfulBuildCount\":0,\"unknownBuildCount\":0},\"byInstanceType\":{}},\"review\":{\"overall\":{\"count\":0,\"lastUpdated\":null,\"stateCount\":0,\"state\":null,\"dueDate\":null,\"overDue\":false,\"completed\":false},\"byInstanceType\":{}},\"deployment-environment\":{\"overall\":{\"count\":0,\"lastUpdated\":null,\"topEnvironments\":[],\"showProjects\":false,\"successfulCount\":0},\"byInstanceType\":{}},\"repository\":{\"overall\":{\"count\":1,\"lastUpdated\":\"2022-12-19T09:09:46.000+0100\"},\"byInstanceType\":{\"stash\":{\"count\":1,\"name\":\"Bitbucket Server\"}}},\"branch\":{\"overall\":{\"count\":0,\"lastUpdated\":null},\"byInstanceType\":{}}}},\"isStale\":false}}"}}]}.
那么有什么方法可以解决这个问题吗?(最好不要删除末尾的三个特定字符,因为将来可能会更改json格式)
非常感谢。
2条答案
按热度按时间rhfm7lfc1#
谢谢你的支持,我已经按照你的建议找到了解决办法.
首先:将json解析为字符串[1]:https://i.stack.imgur.com/Ybvws.png
第二步:使用Regex获取内容
devSummaryJson
[2]:https://i.stack.imgur.com/v6rA4.png我会尝试与groovy和张贴在这里的任何人需要。
wtlkbnrh2#
最简单的正则表达式:第一个月
regex101.com
(?=}]})
是一个正向前查找。它搜索三个特定字符}]}
之前的所有内容。devSummaryJson={.*
搜索开始的位置。无论如何,regex不适用于这类问题,最好的解决方案是使用json解析器。