From b23bbd045102e3dcae9922c38c84f4f312ad8ffb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=2EFernando=20S=C3=A1nchez?= Date: Wed, 18 Apr 2012 17:25:58 +0200 Subject: [PATCH] Added JSON to JASON conversion --- .../dit/gsi/jason/utils/CollectionUtils.java | 61 +++++++++++++++++++ .../dit/gsi/jason/utils/NotationUtils.java | 4 +- .../services/socketio/SocketIOConnector.java | 2 +- 3 files changed, 64 insertions(+), 3 deletions(-) diff --git a/src/java/es/upm/dit/gsi/jason/utils/CollectionUtils.java b/src/java/es/upm/dit/gsi/jason/utils/CollectionUtils.java index b4cb3ce..4d45413 100644 --- a/src/java/es/upm/dit/gsi/jason/utils/CollectionUtils.java +++ b/src/java/es/upm/dit/gsi/jason/utils/CollectionUtils.java @@ -6,8 +6,13 @@ package es.upm.dit.gsi.jason.utils; import jason.asSyntax.Literal; import java.util.Collection; +import java.util.Iterator; import java.util.LinkedList; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + /** * * Project: Web40SOJason @@ -84,4 +89,60 @@ public abstract class CollectionUtils { return strArray; } + + public static String toPerceptsObject(JSONObject jso){ + StringBuilder sb = new StringBuilder(); + Iterator it = jso.keys(); + while(it.hasNext()){ + String key = it.next(); + try { + Object temp= jso.get(key); + String res = toPercepts(temp); + sb.append(key+"("); + sb.append(res); + sb.append(")"); + } catch (JSONException e) { + e.printStackTrace(); + } + if(it.hasNext()){ + sb.append(","); + } + } + return sb.toString(); + + } + + public static String toPerceptsArray(JSONArray jsa){ + StringBuilder sb = new StringBuilder(); + int top = jsa.length(); + int topm = top-1; + sb.append("["); + for(int i=0;i