Deserialize JSON Data by JSON.Net [closed] - c#

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I'm now trying to process some JSON data by using JSON.NET
but i have no idea how to solve it.
The JSON String is very long, so i make it a file click me
My goal is to deserialize to an array what type is bikeData
public class bikeData
{
public string sno { get; set; }
public string sna { get; set; }
public string sarea { get; set; }
public string ar { get; set; }
public string tot { get; set; }
public string sbi { get; set; }
public string bemp { get; set; }
public float lat { get; set; }
public float lng { get; set; }
public string mday { get; set; }
public string sv { get; set; }
public bikeData()
{
}
}
Hope anyone can help me.

Try:
JsonConvert.DeserializeObject<IDictionary<string, bikeData>>()

This should do the job for you:
vara bikeDataObjects = JsonConvert.DeserializeObject<List<bikeData>>(jsonString);

Related

How can l fix these Data Annotation Errors [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed last month.
Improve this question
namespace Network_Management_System
{
class validation
{
// Validation for login_input
static void LoginValidation()
{
[Required]
private string Username { get; set; }
[Required]
[EmailAddress]
public string Email { get; set; }
[Required]
[RegularExpression("W+")]
public string Password { get; set; }
}
}
}
static void LoginValidation()
is a function. Those attributes can be applied to properties of a class. For example:
class Validation
{
[Required]
private string Username { get; set; }
[Required]
[EmailAddress]
public string Email { get; set; }
[Required]
[RegularExpression("W+")]
public string Password { get; set; }
public Validation()
{
}
}

Nested Json Parsing to c#(Console Application) [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
I need to parse Json into C# (Console Application) and also need to view the parsed data in a datatable.
I have tried to generate the classes as far as I know.
Code:
{
"RLC": [
{
"PAR": ""
},
{
"PAR": ""
},
{
"PAR": ""
}
],
"PR":
Please help out.
you can use the below c# class to serialize the json
// Root myDeserializedClass = JsonConvert.DeserializeObject<Root>(myJsonResponse);
public class RecordLocator
{
public string PNR { get; set; }
}
public class PNRAmount
{
public string BalanceDue { get; set; }
public string AuthorizedBalanceDue { get; set; }
public string SegmentCount { get; set; }
public string PassiveSegmentCount { get; set; }
public string TotalCost { get; set; }
public string PointsBalanceDue { get; set; }
public string TotalPointCost { get; set; }
public List<object> AlternateCurrencyCode { get; set; }
public string AlternateCurrencyBalanceDue { get; set; }
}
public class Root
{
public List<RecordLocator> RecordLocator { get; set; }
public PNRAmount PNRAmount { get; set; }
}

How to deserialize strange JSON format in C# [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I have this JSON response from a server:
"{\"Data\":[{\"AI\":\"(00)103002310000531111\",\"BatchId\":157,\"LogisticLevel\":7,\"ParentId\":-1,\"State\":1,\"SyncState\":-1,\"InternalID\":86996,\"ModifyReason\":null,\"AggregationDate\":\"1900-01-01T00:00:00\",\"CommissioningDate\":\"1900-01-01T00:00:00\",\"DecommissioningDate\":\"1900-01-01T00:00:00\",\"NumberOfChildren\":0,\"RejectCode\":-1,\"ShippingDate\":\"1900-01-01T00:00:00\",\"TotalNumberOfUnits\":1,\"CompanyPrefix\":\"030023\",\"FilterValue\":7,\"PackLevel\":1,\"ReferenceCode\":\"\",\"Schema\":1,\"SerialNumber\":\"1000053111\",\"IsGood\":true,\"Children\":[]}],\"Code\":10,\"Message\":\"Data retrieved\"}"
My responsbody it's wrong...much slashes...why ?
I serialize data with Newtonsoft JSON.
But the format isn't correct, I receive an error while deserializing on the client.
I saw that there're slashes in the JSON string. How can I solve this?
I use C#.
Your Json is valid and can be deserialized using JsonConvert:
public class Datum
{
public string AI { get; set; }
public int BatchId { get; set; }
public int LogisticLevel { get; set; }
public int ParentId { get; set; }
public int State { get; set; }
public int SyncState { get; set; }
public int InternalID { get; set; }
public object ModifyReason { get; set; }
public DateTime AggregationDate { get; set; }
public DateTime CommissioningDate { get; set; }
public DateTime DecommissioningDate { get; set; }
public int NumberOfChildren { get; set; }
public int RejectCode { get; set; }
public DateTime ShippingDate { get; set; }
public int TotalNumberOfUnits { get; set; }
public string CompanyPrefix { get; set; }
public int FilterValue { get; set; }
public int PackLevel { get; set; }
public string ReferenceCode { get; set; }
public int Schema { get; set; }
public string SerialNumber { get; set; }
public bool IsGood { get; set; }
public List<object> Children { get; set; }
}
public class RootObject
{
public List<Datum> Data { get; set; }
public int Code { get; set; }
public string Message { get; set; }
}
JsonConvert.DeserializeObject<RootObject>(
"{\"Data\":[{\"AI\":\"(00)103002310000531111\",\"BatchId\":157,\"LogisticLevel\":7,\"ParentId\":-1,\"State\":1,\"SyncState\":-1,\"InternalID\":86996,\"ModifyReason\":null,\"AggregationDate\":\"1900-01-01T00:00:00\",\"CommissioningDate\":\"1900-01-01T00:00:00\",\"DecommissioningDate\":\"1900-01-01T00:00:00\",\"NumberOfChildren\":0,\"RejectCode\":-1,\"ShippingDate\":\"1900-01-01T00:00:00\",\"TotalNumberOfUnits\":1,\"CompanyPrefix\":\"030023\",\"FilterValue\":7,\"PackLevel\":1,\"ReferenceCode\":\"\",\"Schema\":1,\"SerialNumber\":\"1000053111\",\"IsGood\":true,\"Children\":[]}],\"Code\":10,\"Message\":\"Data retrieved\"}"
).Dump();
String json= "{\"Data\":[{\"AI\":\"(00)103002310000531111\",\"BatchId\":157,\"LogisticLevel\":7,\"ParentId\":-1,\"State\":1,\"SyncState\":-1,\"InternalID\":86996,\"ModifyReason\":null,\"AggregationDate\":\"1900-01-01T00:00:00\",\"CommissioningDate\":\"1900-01-01T00:00:00\",\"DecommissioningDate\":\"1900-01-01T00:00:00\",\"NumberOfChildren\":0,\"RejectCode\":-1,\"ShippingDate\":\"1900-01-01T00:00:00\",\"TotalNumberOfUnits\":1,\"CompanyPrefix\":\"030023\",\"FilterValue\":7,\"PackLevel\":1,\"ReferenceCode\":\"\",\"Schema\":1,\"SerialNumber\":\"1000053111\",\"IsGood\":true,\"Children\":[]}],\"Code\":10,\"Message\":\"Data retrieved\"}";
dynamic bsObj = JsonConvert.DeserializeObject<dynamic>(json);
Console.WriteLine(bsObj.ToString());
Console.WriteLine(bsObj.Data[0].BatchId.ToString()); //157
Console.WriteLine(bsObj.Code.ToString()); // 10
Console.WriteLine(bsObj.Message.ToString()); // Data retrieved

How do I convert json.net property is contiguous? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
dataModel = [{"ASB_Base_1":0,"ASB_Idx_1":0,"ASB_Name_Idx_1":"non","ASB_Base_2":0,"ASB_Idx_2":0,"ASB_Name_Idx_2":"non","ASB_Base_3":0,"ASB_Idx_3":0,"ASB_Name_Idx_3":"non"},
{"ASB_Base_1":0,"ASB_Idx_1":0,"ASB_Name_Idx_1":"non","ASB_Base_2":0,"ASB_Idx_2":0,"ASB_Name_Idx_2":"non","ASB_Base_3":0,"ASB_Idx_3":0,"ASB_Name_Idx_3":"non"},
{"ASB_Base_1":0,"ASB_Idx_1":0,"ASB_Name_Idx_1":"non","ASB_Base_2":0,"ASB_Idx_2":0,"ASB_Name_Idx_2":"non","ASB_Base_3":0,"ASB_Idx_3":0,"ASB_Name_Idx_3":"non"}]
The above data in the model.The format is different from the name of the key looks.
public class dataModel
{
public int ASB_Base;
public int ASB_Idx;
public int ASB_Name_Idx;
}
void LoadJsonData(string jsonData)
{
List<dataModel> dataModelList = JsonConvert.DeserializeObject<List<dataModel>>(jsonData);
}
I want to bring in the form of a list, what should I do? Please Help!
Your class should be defined like this:
public class dataModel
{
public int ASB_Base_1 { get; set; }
public int ASB_Idx_1 { get; set; }
public string ASB_Name_Idx_1 { get; set; }
public int ASB_Base_2 { get; set; }
public int ASB_Idx_2 { get; set; }
public string ASB_Name_Idx_2 { get; set; }
public int ASB_Base_3 { get; set; }
public int ASB_Idx_3 { get; set; }
public string ASB_Name_Idx_3 { get; set; }
}

How to parse that json response? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
I am tired about parsing that json response :
I prepared class something for model:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Announcements
{
public class Private
{
public string created_at { get; set; }
public int id { get; set; }
public string text { get; set; }
public string title { get; set; }
public string updated_at { get; set; }
public int user_id { get; set; }
}
public class User
{
public string first_name { get; set; }
public int id { get; set; }
public string last_name { get; set; }
}
public class Public
{
public string created_at { get; set; }
public int id { get; set; }
public string text { get; set; }
public string title { get; set; }
public User user { get; set; }
}
public class RootObject
{
public List<Private> #private { get; set; }
public List<Public> #public { get; set; }
}
}
Now time to deserialize response :
var tempUsersArray = JsonConvert.DeserializeObject<Announcements.RootObject>(response.Content);
and this makes a app crash...
Anyone have idea what i do wrong?
You don't define permission for class, please chnge class Announcements to public class Announcements. Now it should work properly, test this tip please.

Categories

Resources