gpt4 book ai didi

java - 如何获取特定字符的子字符串

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

有特定的子字符串,例如:

{"access_token":"TAeJxtzLtqwzAYQOG30WJkFFk3DxpCCKkhdUKdXcjSL2NqR0ayA3n7ZujQ0o7fGY4ZvbaESKuYw3XlJGbKc9w7FzCBPlBeMy4qj8yWk17j7OyKzCPoHeNUKkkIfTF_U1BFkdXTYqY4LJO9m21EXrvnDDnE6FHSgQbFgQRMhaeY1dLhXgDFsq93FqSvpKhR1gNEY71PkPPrFT-3pfybivPl1HS35tCZ63nftk17Kuw6l3lcwWRIj9HBLxT72_ulu74dP47Fz12CYcxrepb_RbTp2d7tAOkLEB1lYw2e3ddff00f03d82e9b36211220a974ae8b56c0263120c34a25a6c40c91a7f0fd","expires_in":179,"domain":"","username":"","firstname":"","lastname":"","email":"","roles":["","",""],"":true,"":

token的长度是动态的,其他字段也一样。我想做的是提取子字符串 TAeJxtzLtqwzAYQOG30WJkFFk3DxpCCKkhdUKdXcjSL2NqR0ayA3n7ZujQ0o7fGY4ZvbaESKuYw3XlJGbKc9w7FzCBPlBeMy4qj8yWk17j7OyKzCPoHeNUKkkIfTF_U1BFk dXTYqY4LJO9m21EXrvnDDnE6FHSgQbFgQRMhaeY1dLhXgDFsq93FqSvpKhR1gNEY71PkPPrFT-3pfybivPl1HS35tCZ63nftk17Kuw6l3lcwWRIj9HBLxT72_ulu74dP47Fz12CYcxrepb_ RbTp2d7tAOkLEB1lYw2e3ddff00f03d82e9b36211220a974ae8b56c0263120c34a25a6c40c91a7f0fd

因此,必须提供 subString 函数的第二个参数来标识该字符串中的第一个“,”。有人可以帮忙吗?

最佳答案

看起来像 JSON。使用 JSON 解析器,例如 org.Json,如下所示:

import org.json.*;


JSONObject obj = new JSONObject(" your string ");
String pageName = obj.getJSONObject("pageInfo").getString("pageName");

JSONArray arr = obj.getJSONArray("posts");
for (int i = 0; i < arr.length(); i++)
{
String post_id = arr.getJSONObject(i).getString("access_token");
......
}

关于java - 如何获取特定字符的子字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34794400/

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