valid json from arduino web server

Hi,

this function prints json,

void outputJson(EthernetClient client)

{
  client.print("{\"arduino\":[{\"location\":\"outdoor\",\"outdoorTempInC\":\"");
  client.print(outdoorTempInC);
  client.print("\", \"outdoorTempInF\":\"");
  client.println(outdoorTempInF);
  client.print("\"},{\"location\":\"indoor\",\"celsius\":\"");
  client.print(indorTempinC);
  client.print("\"}]}");
  client.println();
}

but above at value of outdoorTempInF, i am getting space below you can see after 72.94

{"arduino":[{"location":"outdoor","outdoorTempInC":"23.30", "outdoorTempInF":"73.94 "}, {"location":"indoor","celsius":"25.50"}]}

where is this space coming from, client.print(""},{"location":"indoor","celsius":"");
wdoes not add any space AFAIcan see. secondly when I fetch this URL from web page i get error saying json parsing error although http://jsonlint.com says SON Parse error: Unterminated string , what is going on ?

I can't see where the extra space is coming from but if you have enough program space and/or need other json conversion I recommend this library which will correctly construct json for you. Don't be put off by it's many features, it's actually quite easy to use.

Why are you using client.println()? You are using client.print() on the rest.

quilkin have a good idea. It is a pretty good library.

But btw.. I chek your JSON object with JSON validator.. and return valid... maybe your problem is elsewhere..

  client.print("{\"arduino\":[{\"location\":\"outdoor\",\"outdoorTempInC\":\"");
  client.print(outdoorTempInC);
  client.print("\", \"outdoorTempInF\":\"");
  client.println(outdoorTempInF);
  client.print("\"},{\"location\":\"indoor\",\"celsius\":\"");
  client.print(indorTempinC);
  client.print("\"}]}");
  client.println();

Why are you sending the outdoor temperature in C and F, but sending the indoor temperature only in C? What weird part of the world do you live in that uses both units of measure?

@PaulS

Canada for once.. :stuck_out_tongue:

Regards. Nitrof

nitrof:
@PaulS

Canada for once.. :stuck_out_tongue:

Regards. Nitrof

So you weirdos use F for indoor temperatures and C for outdoor temperatures? Strange. I thought Canadians were smarter than that, eh.