i am trying to convert JSON to object following is my json
{"entity":"event","account_id":"acc_8yTsyb2WJOlcka","event":"payment.captured","contains":["payment"],"payload":{"payment":{"entity":{"id":"pay_AKR45WLH0g1ANu","entity":"payment","amount":100,"currency":"INR","status":"captured","order_id":"order_AKR41LsWIgOAB1","invoice_id":null,"international":false,"method":"netbanking","amount_refunded":0,"refund_status":null,"captured":true,"description":"Admission Fees","card_id":null,"bank":"SBIN","wallet":null,"vpa":null,"email":"xxxxx.xxxx#xxx.xxx","contact":"xxxxx","notes":{"address":"NA","merchant_order_id":"2516"},"fee":2,"tax":0,"error_code":null,"error_description":null,"created_at":1528367383}}},"created_at":1528367384}
and the code I am trying to convert to object is
jsonString = JsonConvert.SerializeObject(documentContents);
RazorPayPayload desJsonString = JsonConvert.DeserializeObject<RazorPayPayload>(jsonString);
and the classes where I want to deserialized
public class RazorPayPayload
{
public string entity { get; set; }
public string account_id { get; set; }
public string events { get; set; }
public List<string> contains { get; set; }
public payments payload { get; set; }
public string created_at { get; set; }
}
public class payments
{
public Entities payment { get; set; }
}
public class notes
{
public string address { get; set; }
public string merchant_order_id { get; set; }
public string source { get; set; }
}
public class Entities
{
public Entity entity { get; set; }
}
public class Entity
{
public string id { get; set; }
public string entity { get; set; }
public string amount { get; set; }
public string currency { get; set; }
public string order_id { get; set; }
public string invoice_id { get; set; }
public string international { get; set; }
public string method { get; set; }
public string amount_refunded { get; set; }
public string refund_status { get; set; }
public string captured { get; set; }
public string description { get; set; }
public string card_id { get; set; }
public string bank { get; set; }
public string wallet { get; set; }
public string vpa { get; set; }
public string email { get; set; }
public string contact { get; set; }
public notes notes { get; set; }
public string fee { get; set; }
public string tax { get; set; }
public string error_code { get; set; }
public string error_description { get; set; }
}
I am getting the error "Error converting value to type 'FeePayr_Razor_Webhook.RazorPayPayload'"
Have you tried changing:
{"entity":"event","account_id":"acc_8yTsyb2WJOlcka","event":
to
{"entity":"event","account_id":"acc_8yTsyb2WJOlcka","events":
That would better match your class definition. Or rename your class field to event.
There is a useful visual studio function for converting a json object to c# classes.
Copy the JSON into the clipboard. (helps if the JSON object properties holds data, to determine the data type)
Go to visual studio and place cursor where you'd like to paste in the c# classes.
click edit => paste special => paste json as classes
I want to make the simple application to use with my PBX. I want to manage the providers and Lines tat connected to my PBX. The main objects are Provider and Line. Every provider has some lines connected to it. Lines can be added or deleted enabled or disabled and reserved. I want to keep the status of lines and history of actions in one table. Does this right solution or I need to create another table for history?
public class Line
{
public int LineId { get; set; }
public Provider Provider { get;set;}
public string Login { get; set; }
public string Pass { get; set; }
public string Domain { get; set; }
public string ProjectOwner { get; set; }
public string Project { get; set; }
public string OutNumber { get; set; }
public string InNumber { get; set; }
public string Description { get; set; }
public DateTime Begin_datetime { get; set; }
public DateTime End_datetime { get; set; }
public Human TechGuy { get; set; }
public Human Manager { get; set; }
}
public class Provider
{
public int ProviderId { get; set; }
public string Name { get; set; }
public string OurSideData { get; set; }
public string TheirSideData { get; set; }
public string Description { get; set; }
public DateTime Begin_datetime { get; set; }
public DateTime End_datetime { get; set; }
public Currency Currency { get; set; }
}
What is the best solution for the code first model creating in the logic like that? Maybe I need to add some additional fields?
You need another table for history. Something like:
public class Line
{
public int LineId { get; set; }
public virtual Provider Provider { get; set; }
public string Login { get; set; }
public string Pass { get; set; }
public string Domain { get; set; }
public string ProjectOwner { get; set; }
public string Project { get; set; }
public string OutNumber { get; set; }
public string InNumber { get; set; }
public string Description { get; set; }
public DateTime Begin_datetime { get; set; }
public DateTime End_datetime { get; set; }
public Human TechGuy { get; set; }
public Human Manager { get; set; }
public virtual ICollection<LineStatusHistory> ChangeHistory { get; } = new HashSet<LineStatusHistory>();
}
public class LineStatusHistory
{
[Key( )]
public int LineId { get; set; }
[Key()]
public int LineStatusHistoryId { get; set; }
public virtual Line Line { get; set; }
public DateTime ChangeDate { get; set; }
public string Change { get; set; }
}
public class Provider
{
public int ProviderId { get; set; }
public string Name { get; set; }
public string OurSideData { get; set; }
public string TheirSideData { get; set; }
public string Description { get; set; }
public DateTime Begin_datetime { get; set; }
public DateTime End_datetime { get; set; }
public Currency Currency { get; set; }
public virtual ICollection<Line> Lines { get; } = new HashSet<Line>();
}
I am using multiple levels of JSON data coming into php from a C# application, as in:
public class User_Group
{
public int ID_UserGroup { get; set; }
public string Name_UserGroup { get; set; }
public int UserID { get; set; }
}
public class User_Role
{
public int ID_User { get; set; }
public string Role_User { get; set; }
public string User_Role_Description { get; set; }
public List<User_Group> UserGroup { get; set; }
}
public class Stand_Orte
{
public int ID { get; set; }
public string Bezeichnung { get; set; }
public List<Modul> modul { get; set; }
}
public class Modul
{
public string ID { get; set; }
public string Seriennummer { get; set; }
public string Bezeichnung { get; set; }
public string StandortID { get; set; }
public List<Mess_Kanal> MessKanal { get; set; }
}
public class Mess_Kanal
{
public string ID { get; set; }
public string ModulID { get; set; }
public List<LogMess_Daten> LogMessDaten { get; set; }
}
public class LogMess_Daten
{
public string KanalID { get; set; }
public string Zeitstempel { get; set; }
}
public class RootObject
{
public int ID_Project { get; set; }
public string Name_Project { get; set; }
public int Receiver_ID { get; set; }
public string Receiver_Name { get; set; }
public int UserID { get; set; }
public User_Role UserRole { get; set; }
public Stand_Orte Standorte { get; set; }
}
I have an issue with accessing the 3rd level data elements.
For Eg., I am able to get the values uptil Project-> Stand_Orte-> Modul. but after that Project-> Stand_Orte-> Modul-> MessKanal Throws an error in PHP as " Trying to get property of non-object ".
I tried the following:
$phpArray['project']->Standorte[0]->modul[0]->MessKanal[0]->ID
$messkanals=$phpArray->Standorte->modul->MessKanal;
And then used a "foreach ($messkanals as $messkanal)" to insert MessKanal data into MYSQL.
it gives me the following errors respectively.
Cannot use object of type stdClass as array
Trying to get property of non-object
does anyone have any idea?
Thanks,
Revathy
I followed a Tutorial a few weeks ago which shows how to create a simple ASP.NET MVC 3 App (http://www.asp.net/mvc/tutorials/mvc-music-store-part-1).
Now I created another app that is actually doing something very simple, but I cant make Visual Studio 2010 automatically creating a View that shows a selection of the 1:n connection.
The program is a simple News system with a relation NewsEntry.NewsCategory to NewsCategory.ID.
NewsEntry.cs
public class NewsEntry
{
public int ID { get; set; }
public string Title { get; set; }
public string ShortText { get; set; }
public string Text { get; set; }
public DateTime PublishDate { get; set; }
public DateTime UnpublishDate { get; set; }
public NewsCategory NewsCategory { get; set; }
}
NewsDB.cs
public class NewsCategory
{
public int ID { get; set; }
public string Name { get; set; }
public List<NewsEntry> News { get; set; }
}
NewsDB.cs
public class NewsDB : DbContext
{
public DbSet<NewsEntry> NewsEntry { get; set; }
public DbSet<NewsCategory> NewsCategory { get; set; }
}
So my question is what is missing that VS is not creating a view with category in a drop down list?
It obviously helped to add a NewsCategoryId field:
public class NewsEntry
{
public int NewsEntryId { get; set; }
public string Title { get; set; }
public string ShortText { get; set; }
public string Text { get; set; }
public DateTime PublishDate { get; set; }
public DateTime UnpublishDate { get; set; }
public int NewsCategoryId { get; set; }
public virtual NewsCategory NewsCategory { get; set; }
}
I'm trying to create a POCO object called Friend.cs. I can't seem to create inline properties for the IList.
public class User
{
public string ID { get; set; }
public string Name { get; set; }
public string Rating { get; set; }
public string Photo { get; set; }
public string Reputation { get; set; }
public string Group { get; set; }
public string GroupColor { get; set; }
public string PostCount { get; set; }
public string PostPerDay { get; set; }
public string JoinDate { get; set; }
public string Views { get; set; }
public string LastActive { get; set; }
public string Title { get; set; }
public string Age { get; set; }
public string Birthday { get; set; }
public string Sex { get; set; }
public string LinkedIn { get; set; }
public string Facebook { get; set; }
public string Twitter { get; set; }
public IList<Friend> {get???
}
Thanks for the help!
You forget the name of the property:
public IList<Friend> Friends {get; set;}
should work.
Your missing the property name
ie
Public IList<Friend> Friends { get; set; }
public class User
{
public IList<Friend> Friends
{
get { return _friends; }
set { _friends = new List<Friend>(value); }
}
private List<Friend> _friends;
}