using json with an http client
in
Contributed Library Questions
•
1 year ago
Hi all,
I'm struggling for hours to create a json object from an incoming string using the json library for processing. ( https://github.com/agoransson/JSON-processing) I've created a client to make the request.
As the returned data is an http header I use:
HTTP http = new HTTP();
In the draw() method I put:
This is the result that is returned:
I want to get the session id from this result. I thought it would be easy but I keep getting errors about the returned string. With the code above I get this error:
org.json.JSONException: Expected ':' and instead saw '
' at 17 [character 0 line 5]
I've tried all kinds of variations: using the HTTPTokener and Cookie but somehow I can't seem to work with this string. What am I doing wrong?
Any help would be greatly appreciated, best danielle.
I'm struggling for hours to create a json object from an incoming string using the json library for processing. ( https://github.com/agoransson/JSON-processing) I've created a client to make the request.
As the returned data is an http header I use:
HTTP http = new HTTP();
In the draw() method I put:
- void draw() {
- if (c.available() > 0) {
- try{
- dataIn = c.readString();
- println(dataIn);
- println(http.toJSONObject(dataIn));
- }
- catch (JSONException e){
- println(e);
- }
- }
- }
This is the result that is returned:
- HTTP/1.1 200 OK
- Server: nginx/1.0.8
- Date: Fri, 30 Mar 2012 15:00:04 GMT
- Content-Type: application/json
- Transfer-Encoding: chunked
- Connection: keep-alive
- X-Powered-By: PHP/5.3.10-1~dotdeb.1
- Access-Control-Allow-Credentials: true
- Access-Control-Allow-Methods: POST, GET, PUT, OPTIONS, DELETE
- X-SESSION_ID: 30244f75ca74b12b40.79682968
- Access-Control-Expose-Headers: X-SESSION_ID
- Access-Control-Allow-Origin: *
- Access-Control-Allow-Headers: X-SESSION_ID, Content-Type
- Access-Control-Max-Age: 1728000
- Set-Cookie: session_id=30244f75ca74b12b40.79682968
- 2c
- {"session_id":"30244f75ca74b12b40.79682968"}
- 0
I want to get the session id from this result. I thought it would be easy but I keep getting errors about the returned string. With the code above I get this error:
org.json.JSONException: Expected ':' and instead saw '
' at 17 [character 0 line 5]
I've tried all kinds of variations: using the HTTPTokener and Cookie but somehow I can't seem to work with this string. What am I doing wrong?
Any help would be greatly appreciated, best danielle.
1