[英]how can i split a string inside curly braces?
I have a string which looks like this 我有一个看起来像这样的字符串
[{"TransactionId":"3574780600039252015-12-24 T 14:22:03"
Now I want to split only the text where the "TransactionId" will be part one and after :
will be the second part. 现在,我只想分割文本,其中“ TransactionId”将是第一部分,而
:
之后将是第二部分。
Code I've tried : 我尝试过的代码:
String[] transid_result = result.split(":");
String part1 = transid_result[0];
String part2 = transid_result[1];
The result is 结果是
part1
contains [{"TransactionId
part1
包含[{"TransactionId
part2
contains "3574780600039252015-12-24 T 14
part2
包含"3574780600039252015-12-24 T 14
I want part2
to contain "3574780600039252015-12-24 T 14:22:03"
我希望第2
part2
包含"3574780600039252015-12-24 T 14:22:03"
Can anyone help me ? 谁能帮我 ?
You could search for the first :
and manually split by that: 您可以搜索第一个
:
然后手动拆分:
int firstColon = result.indexOf(":");
String part1 = result.substring(0,firstColon);
String part2 = result.substring(firstColon+1, result.length());
If you're sure the data will always be in this format, then you could use 如果您确定数据将始终采用这种格式,则可以使用
String[] elements = result.split("\"");
String transactionId = elements[3];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.