title: How to extract JSON from this HTTP request in Java
body: <p>The method below is hit or miss if it parses the request properly...</p>
  
  <p>Here is what the request looks like:</p>
  
  <pre><code>POST /addEvent/ HTTP/1.1
  Host: localhost:1234
  Content-Type: multipart/form-data; boundary=Boundary+0xAbCdEfGbOuNdArY
  Accept-Encoding: gzip, deflate
  Content-Length: 201
  Accept-Language: en;q=1, fr;q=0.9, de;q=0.8, ja;q=0.7, nl;q=0.6, it;q=0.5
  Accept: application/json
  Connection: keep-alive
  User-Agent: XXXXXXXXXXXXXXXXXX
  
  --Boundary+0xAbCdEfGbOuNdArY
  Content-Disposition: form-data; name="userInfo"
  
  {   "user_id" : 1,   "value" : "Water",   "typeCode" : "Searched" } 
  </code></pre>
  
  <p>Here is how we are extracting it now...</p>
  
  <pre><code>//Key where the request begins
  String keyString = "\"userInfo\"";
  
  //Get the index of the key
  int end = bufferedJson.lastIndexOf("\"userInfo\"");
  
  //Create substring at beginning of the json
  String json = bufferedJson.substring(end+keyString.length(), bufferedJson.length());
  
  //Convert json to feed item
  Gson gson = new Gson();
  Event eventItem = gson.fromJson(json, Event.class);
  </code></pre>
  
  <p>I get this error pretty often:</p>
  
  <pre><code>Expected BEGIN_OBJECT but was STRING at line 1 column 1
  </code></pre>
  
  <p>How can we parse this efficiently?</p>