How do i deserialize a Jsonp response into splited string

deserialize json
deserialize json string to object c#
c# json to object
multiple json objects in one file c#
newtonsoft json
deserialize json array c#
deserialize response c#
deserialize json to dynamic object c#
var responseData = await response.Content.ReadAsStringAsync();
var msg = JsonConvert.DeserializeObject<string>(responseData);
string[] result = msg.Split(',');
string statuscode = result[0];
string RRR = result[1];
string status = result[2];

The code above shows my response after sending a request to an API with a responseData as jsonp ({"statuscode":"025","RRR":"260007663696","status":"Payment Reference generated"}) When i ran the code, i got an error message complaining about var msg = JsonConvert.DeserializeObject<string>(responseData);

How do i go about converting my jsonp response into splitted string values?

You can use Regex to convert your JSONP to JSON, by stripping the outer function away and extracting only the JSON inside the brackets:

var jsonp = "jsonp({ \"statuscode\":\"025\",\"RRR\":\"260007663696\",\"status\":\"Payment Reference generated\"})";
var jsonMatch = Regex.Match(jsonp, @"\((?<json>.*)\)");
var json = jsonMatch.Groups["json"].Value;

After that, you can deserialize using your preferred method with the JSON.Net library. Here's one way using the Newtonsoft.Json.Linq namespace:

var token = JToken.Parse(json);
var status = token["status"].Value<string>();
var statusCode = token["statuscode"].Value<string>();
var rr = token["RRR"].Value<string>();

[Solved] Deserialize json response string to class, Its a JSON array so parse it with Student Array. Hide Copy Code. Student[] Students = JsonConvert.DeserializeObject<Student[]>(json); foreach  If you aren't creating a class to deserialize your JSON, you can convert your JSON to a dynamic object and access the properties freely: dynamic result = JObject.Parse(responseData); string statuscode = result.statuscode; string RRR = result.RRR; string status = result.status;

Your JSON payload represents an object with 3 properties. I recommend making a class that represents this object so you can serialize/deserialize:

public class SomeObject  //Rename to something more fitting
{
    public string StatusCode {get;set;}
    public string RRR {get;set;}
    public string Status {get;set;}
}

Then when you deseralize, use this new class as the generic parameter (not string like you are currently doing):

var someObj = JsonConvert.DeserializeObject<SomeObject>(json);

Now you can access the properties like you would any other instance:

Console.WriteLine(someObj.Status);
// etc, etc

Fiddle here

Serverless computing in Azure with .NET, documentList.cs: Let's explore the documentList class in the following code the method will split the text into single sentences, assign them consecutive string IDs, Then, it will serialize the resulting object to a JSON string and return it to the  // The next line of code will only run after the response has been received // Create a new Deserializer to be able to parse the JSON object RestSharp. Deserializers. JsonDeserializer deserial = new JsonDeserializer (); //To deserialize into a simple variable, use the <Dictionary<string, string>> type var JSONObj = deserial.

If you aren't creating a class to deserialize your JSON, you can convert your JSON to a dynamic object and access the properties freely:

dynamic result = JObject.Parse(responseData);
string statuscode = result.statuscode;
string RRR = result.RRR;
string status = result.status;

[Solved] Split multiple json data in json file format as object and as , Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type ' jsonreader.SpectrumData[]' because the type requires a JSON array (  DeSerialize JSON Array to List of String using JSONPath JsonPath class has two overloaded methods (jsonPath.getList) to extract JSON nodes as a Java List. Here are the methods JsonPath.getList (String) method lets us get the searched nodes as a List of String

ServiceStack/ServiceStack.Text: .NET's fastest JSON, JSV , writer) T JsonSerializer.DeserializeFromString<T>(string value) T JsonSerializer. Any IDictionary is serialized into a standard JSON object, i.e: {" A":1,"B":2,"C":3,"D":4} Split('x'); return new Size { Width = double.Parse(size[0]), Height  hmm .. well, if you were the person who put the JSON together, I would re-do it - I dont see the value for the '1', '2' etc - if you need them as some sort of index/ID, they should be in the

Deserialize Json, JsonString - The string containing the JSON to be deserialized. field and the variable JsonObj in the JsonObject field. Select the value Newtonsoft.Json.Linq. Thank you @fes-sitecore. I am able to deserialize json into custom class collection called jsonData.But i am not sure how i will get the specified data like "EventTime" from json data. how do i use linq query to get the specified field from json data.

Deserializing JSON string to JSON object - Studio, Hi, I'm trying to deserialize a string that contains JSON. The problem is that I can't split the string with the commas because the array will output something like : @kartistenn Assuming you have the Json in a Text File,. I have absolutely no idea how to deserialize this JSON. The ultimate goal is to display the text of an element in a combobox, an then do further queries with the 'ID' of the element selected by the combo box.

Comments
  • You seem to have a misunderstanding of JSON. Your JSON string represents an object with 3 properties (statuscode, RRR and status). You are trying to deserialize into a string which is incorrect. You need to define a class that has those 3 properties in it and deserialize into that
  • Can you post the definition of RemitaResponse in your answer? If you attempted to deserailize into an object and it did not work we need to see that too.
  • Threw exception JsonReaderException: Unexpected character encountered while parsing value: j. Path '', line 0, position 0. Newtonsoft.Json.JsonTextReader.ParseValue()