Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.HashMap;
- public class Parse
- {
- public static void main(String[] args)
- {
- String toParse = "ObjectGUId=1abcde&ObjectType=2&ObjectTitle=maximumoflife&Content=racroi&TimeStamp=2012-11-05T17:20:06.056";
- String[] fields = toParse.split("&");
- String[] t;
- HashMap<String, String> things = new HashMap<String, String>();
- for (int i = 0; i < fields.length; ++i)
- {
- t = fields[i].split("=");
- if (2 == t.length)
- {
- things.put(t[0], t[1]);
- }
- }
- // NOTE this will fail if the keys are not present in the dict.
- // Remember to sanitise your input!
- LogObject logObject = new LogObject(things.get("ObjectGUId"),
- things.get("ObjectType"),
- things.get("ObjectTitle"),
- things.get("Content"),
- things.get("TimeStamp"));
- // NOTE this is not guaranteed to print in sorted order
- for (String k : things.keySet())
- System.out.println(k + ": " + things.get(k));
- System.out.println(logObject);
- }
- static class LogObject
- {
- private String ObjectGUId;
- private String ObjectType;
- private String ObjectTitle;
- private String Content;
- private String TimeStamp;
- public LogObject(String guid, String type, String title,
- String content, String timestamp)
- {
- ObjectGUId = guid;
- ObjectType = type;
- ObjectTitle = title;
- Content = content;
- TimeStamp = timestamp;
- }
- public String toString()
- {
- return ObjectGUId + ", " + ObjectType + ", " + ObjectTitle + ", "
- + Content + ", " + TimeStamp;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement