How can i parse a PHP array from Android SDK?
I dont like others do my duties, but i'm n开发者_如何学JAVAot a RegEx expert and i think you guys would be a great help.
I'm building a newsletter Android app which consumes an array exposed in a http like this:
Array
(
[Last_News] => Array
(
[last-news-1] => Array
(
[ID] => 711
[Title] => Here goes the title text
[Bullet] => Here goes the basic description of the news.
)
)
I'm trying with RegEx this:
String pattern = ".Ultima_Hora. => Array . .ultima_hora-[0-9]*.";
Pattern p = Pattern.compile(pattern);
Matcher m = p.matcher(str);
while (m.find()) { // Find each match in turn; String can't do this.
//String s = m.group();
String s = m.toString();
txt.setText(s);
}
But then, when i run my app, i can see all the text downloaded from my httpclient implementation. Someone can give a example of how i can print the arrays inside [last-news-1]? Thank you very much.
I don't know what kind of flavor Java uses but in PHP I would use the following regexes:
\[ID\] => (.*)
\[Title\] => (.*)
\[Bullet\] => (.*)
Now the problem is if each key is allowed to have newlines in it, in that case I would do:
\[ID\] => ([^\[]*)
\[Title\] => ([^\[]*)
\[Bullet\] => ([^\[]*)
But then it won't match the whole string if it contains a [
but I guess that's the price you have to pay.
精彩评论