more G-Labs products

Author Topic: Help with xml response  (Read 1066 times)

April 23, 2015, 10:46:11 PM
Read 1066 times

codedmind

  • ***
  • Information
  • Full Member
  • Posts: 92
I there, i have the following xml
Code: [Select]
<response>
<device id="22114" type="1" period="5"/>
<data time="1429815600" status="43" current="1366">
<energy>22929984</energy>
<power>314</power>
</data>
</response>
and the following code
Code: [Select]
dynamic test = Net.WebService(url).GetData();

Program.Notify("Test", test.Replace("<","&lt").ToString());
Pause(15);
Program.Notify("Test", test.response.ToString());

The first notify show me the xml (the replace is the only way i can find to see the output) in the second notify however i get an error,    string does not contain a definition for `response'

Any help?

Other question is how can i get the attribute value? (for example device id value)?
« Last Edit: April 23, 2015, 11:00:45 PM by codedmind »

April 24, 2015, 09:13:17 AM
Reply #1

nolio

  • *****
  • Information
  • Global Moderator
  • Posts: 544
You can use this method : http://www.homegenie.it/docs/doxy/a00006.html#a08d047072bdd8bcefd1645de3dc6eda0

in the example :
Code: [Select]
var iplocation = Net.WebService("http://freegeoip.net/json/").GetData();
Program.Notify("IP to Location", iplocation.city);

iplocation.city => city is the name of "XML" Tag.
You can try by calling : http://freegeoip.net/json/ and search city

So in your example : test.energy should return 22929984

April 24, 2015, 09:56:26 PM
Reply #2

codedmind

  • ***
  • Information
  • Full Member
  • Posts: 92
thanks for your reply.

I already try it, that is json, and i use xml... don't know why... but i still have a crc error
`string' does not contain a definition for `energy'
« Last Edit: April 24, 2015, 09:59:04 PM by codedmind »

April 24, 2015, 10:45:04 PM
Reply #3

nolio

  • *****
  • Information
  • Global Moderator
  • Posts: 544
Ok, i think i already do it with XML, but probably a mistake ..
So i don't have any advise on my side. Sorry.