0

I have a below json string and i am trying to get the "Company" array into C# Array

but i could not.. i have gone through other question over web, I found few serialization and Newtonsoft JSON Convert. but i don't have newtonsoft assembly on server as i am using a shared.. is there any way i get the

How can i get values from Json Array in C# Array and Json key value in C# string and integer array type?

I am using .net 4.0

{"Company": ["BMW", "Mercedes"], "Year":["2011","2014"], "request_id":"4"}
3
  • 5
    Considered using the built in .NET JavascriptSerializer? msdn.microsoft.com/en-us/library/… Commented Dec 21, 2015 at 13:07
  • 3
    See this. Commented Dec 21, 2015 at 13:07
  • how about Array? and i am using 4.0 @FᴀʀʜᴀɴAɴᴀᴍ Commented Dec 21, 2015 at 13:09

1 Answer 1

1

Yes, you can do it with REGEX

using System.Text.RegularExpressions;

var jsonString = "{\"Company\": [\"BMW\", \"Mercedes\"], \"Year\":[\"2011\",\"2014\"], \"request_id\":\"4\"}";
var regexPattern = @"""Company"":\s\[(""\w+"".\s?)+";
Regex.Match(jsonString, regexPattern)
//Result => ["Company": ["BMW", "Mercedes"]]

Regex.Match(jsonString, regexPattern).Groups[1]
//["BMW", "Mercedes"]]
Sign up to request clarification or add additional context in comments.

5 Comments

terrible idea to parse json with regex
@FᴀʀʜᴀɴAɴᴀᴍ He want to parse it without JSON.NET, so the best option in this case is Regex
Btw @FᴀʀʜᴀɴAɴᴀᴍ terrible ideia is to downvote the answer because you want to use something that the OP wont.
There are two downvotes. So someone other than me (whom you consider ...) too doesn't like your answer.
If you absolutely cannot use any existing JSON parser, the best course of action would be to write your own. The grammar is quite simple, and it wouldn't be too difficult to make a bug free one.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.