-2

I want Convert Json to Object in C#. Json here is:

[{"value":"e920ce0f-e3f5-4c6f-8e3d-d2fbc51990e4"}].

How to do it using Object.

Question seems silly but it is not so stupid. I have not simple Json, I have IEnumerable and I am getting json from usint JsonResult like this:

new JsonResult(from c in User.Claims where (c.Type.Equals("value")) select new { c.Value });

This linq code does not work on JObject.

Thanks to Tommaso Belluzzo.

Dato Gogshelidze
  • 666
  • 7
  • 20
  • 1
    There are plenty of libraries out there to do that for you. A simple Google search will find many for you. – krillgar Dec 10 '17 at 17:20
  • easy / simple answer to your question is a Simple Google search.. also read the `AskQuestion` link in the upper right hand side of this page ,navigate to `Question Help` and read the section on `How To Ask a Question` – MethodMan Dec 10 '17 at 17:59
  • Dato, take care with your questions. You can get a ban like me. Now i can to ask, but i'll make when i'm certain that the question is single and to make a good question. Take care. If you accept the response from **Tomazzo Belluzo** this help you to get reputation. Then, find out in the google or here before to ask. – pnet Dec 10 '17 at 18:48
  • I have found solution to converting in List: List l = (from c in User.Claims where (c.Type.Equals("value")) select new { c.Value }.ToString()).ToList(); – Dato Gogshelidze Dec 11 '17 at 08:07

1 Answers1

2

Using NewtonSoft Json.NET library (https://www.newtonsoft.com/json), you can do as follows:

JObject result = JObject.Parse(jsonString);

But your Json string looks more like an array, so probably JArray.Parse is what you need to use instead. Documentation with examples here:

https://www.newtonsoft.com/json/help/html/ParseJsonArray.htm

If you want to parse the internal elements as objects, thhe accepted answer of this question should provide you enough hints:

C# Parsing JSON array of objects

Tommaso Belluzzo
  • 23,232
  • 8
  • 74
  • 98
  • Thank you Tommaso Belluzzo. Yes I understand question seems silly but it is not so stupid. I have not simple Json, I have IEnumerable and I am getting json from usint JsonResult like this: new JsonResult(from c in User.Claims where (c.Type.Equals("value")) select new { c.Value }); This linq code does not work on JObject. I am deleting question... Thank you for answer again. – Dato Gogshelidze Dec 11 '17 at 07:31
  • I doubt it can work with Linq. You have to format it. As I said, eventually, work with JArray.Parse. – Tommaso Belluzzo Dec 11 '17 at 07:37