Android parsing how to get value from this XML

just a simple question here. How can I get the return value on this kind of xml

 Art C. Cauyao<$@FBID@$>501912568<$@ENDFBID@$>Tessa Rose 
Brainard<$@FBID@$>510831686<$@ENDFBID@$>
Dan Gangan<$@FBID@$>513545777<$@ENDFBID@$>
C Jhec DawAko<$@FBID@$>523059320<$@ENDFBID@$>Jeremy 

Please see that I am getting Facebook name and Facebook ID Is there any way about that?

EDIT

I found out that it is not an xml but rather A JSON (sorry) now my question really is how can I incorporate that returned value?

EDIT SECOND Sir this what I am doing Parsing it through this

static final String URL_FBFRIEND ="Some URL"+ "getFBFriends.php"; 

Now using that I can now parse some data by using my input values. Here is the code

        XMLparser parser2 = new XMLparser(); 
    parser2.getXmlFromUrl(URL_FBFRIEND); 

      //HTTP POST
      String url_Getmembermob= URL_FBFRIEND ;
      String xml_getMembermob=null;
      try {
      HttpClient httpclient = new DefaultHttpClient();
      HttpPost httppost = new HttpPost(url_Getmembermob);

      List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(4); 
      nameValuePairs.add(new BasicNameValuePair("...", "...."));
      nameValuePairs.add(new BasicNameValuePair("fbID", modGen.facebookID ));
      nameValuePairs.add(new BasicNameValuePair("accToken", modGen.tokenID));
      nameValuePairs.add(new BasicNameValuePair("reqType", "0"));

      Log.i("nameValuePairs", "nameValuePairs=" + nameValuePairs);

        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        HttpResponse httpResponse = httpclient.execute(httppost);

        HttpEntity httpEntity = httpResponse.getEntity();

        xml_getMembermob = EntityUtils.toString(httpEntity);

        Log.i("xml-return",""+ xml_getMembermob);

    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace(); 
    }catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

See that I am logging the returned xml Log.i("xml-return",""+ xml_getMembermob); And thats the output

Sir Ive altered your code` public static List parseUserList(String userData) { List ret = new ArrayList();

    int index = 0;
    while (index < userData.length())
    {
        int startFbTag = userData.indexOf(FB_NAME, index);
        if (index == -1)
        {

            return ret;
        }
        String name = userData.substring(index, startFbTag - index);
        startFbTag += FB_NAME.length(); // Start of the actual data
        int endFbTag = userData.indexOf(FB_ID, startFbTag);
        if (endFbTag == -1)
        {
            throw new IllegalArgumentException("Unterminated start tag");
        }

        fbTagValue = userData.substring(startFbTag, endFbTag - startFbTag);
        Log.i("UserName",fbTagValue);
        //fbId = Long.parseLong(fbTagValue);
        //ret.add(new User(name, fbId));
        index = endFbTag + FB_ID.length();
    }
    return ret;
}

I am getting an error here ** fbTagValue = userData.substring(startFbTag, endFbTag - startFbTag);** what seems to be the problem

Answers


This is pretty horrible format. It's not XML. It's not JSON. Assuming you've already got some sort of User class, and that all the data is in a single String, you could write something like this (completely untested):

private static final String FB_START = "<$@FBID@$>";
private static final String FB_END = "<$@ENDFBID@$>";

public static List<User> parseUserList(String userData)
{
    List<User> ret = new ArrayList<User>();

    int index = 0;
    while (index < userData.length())
    {
        int startFbTag = userData.indexOf(FB_START, index);
        if (index == -1)
        {
            // No tags left. You should check whether you've actually got
            // some data left, and potentially throw an exception. It's not
            // clear what your data format does here.
            return ret;
        }
        String name = userData.substring(index, startFbTag - index);
        startFbTag += FB_START.length(); // Start of the actual data
        int endFbTag = userData.indexOf(FB_END, startFbTag);
        if (endFbTag == -1)
        {
            throw new IllegalArgumentException("Unterminated start tag");
        }

        String fbTagValue = userData.substring(startFbTag, endFbTag - startFbTag);
        long fbId = Long.parseLong(fbTagValue);
        ret.add(new User(name, fbId));
        index = endFbTag + FB_END.length();
    }
    return ret;
}

Need Your Help

JQuery Ajax Performance (JSON)

jquery json

i have a page made AJAX/HTTP Request and the result is JSON formatted .

Who will receive messages first virtual topic subscriber or logical queue consumer?

java apache jms activemq middleware

I am trying to use virtual topic and am unable to find answer to this question, Can anybody help?