Saturday, August 11, 2012

using Json in Java: non file output

I had to write some java code that used JSON format for the final out but did so with out using files:
Here was the soulition to make this happen

while(counter < numOfTags)
{
if(outList[counter].getType() == 0)
temp.addProperty(outList[counter].getTagName(),outList[counter].getFloatData());
else
temp.addProperty(outList[counter].getTagName(),outList[counter].getStringData());
counter++;
}
String outputString = mySon.toJson(temp);

notes:
int counter;
Device[] outList;
Gson mySon = new Gson();
JsonObject temp = new JsonObject();
int numOfTags;

No comments:

Post a Comment