1

I Have a JSON with this values

{"interface":"ALL",
 "dv":"1",
 "alarms":[{"Id":0,
            "Type":"URL",
            "Trigger":"facebook",
            "Output":"video"},
           {"Id":1,
            "Type":"URL",
            "Trigger":"twitter",
            "Output":"video"},
           {"Id":2,
            "Type":"URL",
            "Trigger":"ebay",
            "Output":"video"}
]}

And i would like parse this information to mi C# Code

I do this for Strings tags and works ok

JObject obj = JObject.Parse(json);
String value =(String) obj["dv"]; 

but i have an error for tag Array alarms. I've tried with:

Array value = null;
value =(Array) obj["alarm"]; 

but i get an error (Message=Can not convert Array to byte array. Source=Newtonsoft.Json).

1
  • try to map this json object to a datacontract , you can use link to make the class you can use as datacontract. this link may be helpful in doing that. Commented Feb 25, 2014 at 8:00

4 Answers 4

2

Try convert your alarms into a JArray:

JArray value = null;
value = obj["alarms"] as JArray;
Sign up to request clarification or add additional context in comments.

Comments

0

You could use JavaScriptSerializer for this.
For example:

JavaScriptSerializer jss = new JavaScriptSerializer();
Dictionary<string, object> dict = jss.Deserialize<Dictionary<string, object>>(jsonString);

Comments

0

Using Json.Net

JArray value = null;
value = obj["alarms"] as JArray;

The casting should be JArray

Comments

-2

Your json string has a reserved c# keyword: interface. Try changing this and see if it works.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.