Extracting only a specified part of a string in Android
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
精彩评论