开发者

Extracting only a specified part of a string in Android

开发者 https://www.devze.com 2023-03-25 11:08 出处:网络
Let\'s say I have a string : {\"id\":\"123\",\"xCoord\":\"01.234567\",\"yCoord\":\"89.012345\",\"etc.\":\"etcetc\"}

Let's say I have a string :

{"id":"123","xCoord":"01.234567","yCoord":"89.012345","etc.":"etcetc"}

I want to extract only the xCoord part - the number 01.234567 and put it into a string array String[] xCoords = {};

I cannot use the public String substring (int st开发者_开发问答art, int end) function because in future the id will eventually grow up and I don't have a firm index to use.

What would you suggest me - is there any way of extracting only the symbols after "xCoord":" and before ","y...


The best (and most reliable) option would be to convert your string (which is valid JSON) into an object and reference it that way.

Convert JSON String to Java Object or HashMap

0

精彩评论

暂无评论...
验证码 换一张
取 消