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

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; }
}

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; }
}

Unable to get third level records filtered using Entity Framework [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 1 year ago.
Improve this question
I have the below code structure and would like to get all the record from Unit collection where AmountIsTaxInclusive is true
public class Unit
{
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int UnitID { get; set; }
public string Name { get; set; }
public int UnitStatusID { get; set; }
public virtual Reservation Reservation { get; set; }
}
public class Reservation
{
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int ReservationID { get; set; }
public int ReservationStatusID { get; set; }
public virtual ICollection<ReservationUnits> ReservationUnits
}
public class ReservationUnit
{
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int ReservationUnitID { get; set; }
[Required]
public int ReservationID { get; set; }
public Reservation Reservation { get; set; }
[Required]
public int UnitID { get; set; }
public Unit Unit { get; set; }
public decimal Amount { get; set; }
public bool AmountIsTaxInclusive { get; set; }
public bool IsFixedRate { get; set; }
}
When I tried to filter Reservationunit collection I am getting all records.
Query
var result = _unitOfWork.UnitRepository.GetBySessionIdAndUnit(sessionId, newUnitIds).IncludeFilter(p => p.Reservation).IncludeFilter(y => y.Reservation.ReservationUnit.Where(c => c.AmountIsTaxInclusive == true)).ToList();
The answer is simple. You just need to make an instance of your Context class(let us name it dbContext).
Then call the following line where you want.
var myDesiredList = dbContext.ReservationUnit.where( ru => ru.AmountIsTaxInclusive == true).ToList();
Let me know if you had more information to share.

Deserialize JSON Data by JSON.Net [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 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);

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