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 8 years ago.
Improve this question
How would I go at parsing this JSON? Its an array of arrays; http://extradelar.se/match
I have been googling and trying for hours. What is the right way of doing this?
prove it with an answer
#Aydin Adn, Are you happy? this is how you can write a working code. (Sorry for posting it as an answer, since it is too big for being a comment.)
var lists = JsonConvert.DeserializeObject<List<List<MyObject>>>(jsonInQuestion);
public class MyObj
{
public string match_id { get; set; }
public string account_id { get; set; }
public string clan_id { get; set; }
public string hero_id { get; set; }
public string position { get; set; }
public string team { get; set; }
public string level { get; set; }
public string wins { get; set; }
public string losses { get; set; }
public string concedes { get; set; }
public string concedevotes { get; set; }
public string buybacks { get; set; }
public string discos { get; set; }
public string kicked { get; set; }
public string pub_skill { get; set; }
public string pub_count { get; set; }
public string amm_solo_rating { get; set; }
public string amm_solo_count { get; set; }
public string amm_team_rating { get; set; }
public string amm_team_count { get; set; }
public string avg_score { get; set; }
public string herokills { get; set; }
public string herodmg { get; set; }
public string heroexp { get; set; }
public string herokillsgold { get; set; }
public string heroassists { get; set; }
public string deaths { get; set; }
public string goldlost2death { get; set; }
public string secs_dead { get; set; }
public string teamcreepkills { get; set; }
public string teamcreepdmg { get; set; }
public string teamcreepexp { get; set; }
public string teamcreepgold { get; set; }
public string neutralcreepkills { get; set; }
public string neutralcreepdmg { get; set; }
public string neutralcreepexp { get; set; }
public string neutralcreepgold { get; set; }
public string bdmg { get; set; }
public string bdmgexp { get; set; }
public string razed { get; set; }
public string bgold { get; set; }
public string denies { get; set; }
public string exp_denied { get; set; }
public string gold { get; set; }
public string gold_spent { get; set; }
public string exp { get; set; }
public string actions { get; set; }
public string secs { get; set; }
public string consumables { get; set; }
public string wards { get; set; }
public string time_earning_exp { get; set; }
public string bloodlust { get; set; }
public string doublekill { get; set; }
public string triplekill { get; set; }
public string quadkill { get; set; }
public string annihilation { get; set; }
public string ks3 { get; set; }
public string ks4 { get; set; }
public string ks5 { get; set; }
public string ks6 { get; set; }
public string ks7 { get; set; }
public string ks8 { get; set; }
public string ks9 { get; set; }
public string ks10 { get; set; }
public string ks15 { get; set; }
public string smackdown { get; set; }
public string humiliation { get; set; }
public string nemesis { get; set; }
public string retribution { get; set; }
public string used_token { get; set; }
public string nickname { get; set; }
}
Related
This question already has answers here:
C# keywords as a variable
(4 answers)
Use the long reserved word as a variable name in C#
(5 answers)
Closed 2 years ago.
I`m working on a project using .Net core, now I have Git hub's repository search api that I need to convert the data to c# object.
Using Json2Csharp (https://json2csharp.com/) I got that class:
public class Root {
public int id { get; set; }
public string node_id { get; set; }
public string name { get; set; }
public string full_name { get; set; }
public bool private { get; set; }
public Owner owner { get; set; }
public string html_url { get; set; }
public string description { get; set; }
public bool fork { get; set; }
public string url { get; set; }
public string forks_url { get; set; }
public string keys_url { get; set; }
public string collaborators_url { get; set; }
public string teams_url { get; set; }
public string hooks_url { get; set; }
public string issue_events_url { get; set; }
public string events_url { get; set; }
public string assignees_url { get; set; }
public string branches_url { get; set; }
public string tags_url { get; set; }
public string blobs_url { get; set; }
public string git_tags_url { get; set; }
public string git_refs_url { get; set; }
public string trees_url { get; set; }
public string statuses_url { get; set; }
public string languages_url { get; set; }
public string stargazers_url { get; set; }
public string contributors_url { get; set; }
public string subscribers_url { get; set; }
public string subscription_url { get; set; }
public string commits_url { get; set; }
public string git_commits_url { get; set; }
public string comments_url { get; set; }
public string issue_comment_url { get; set; }
public string contents_url { get; set; }
public string compare_url { get; set; }
public string merges_url { get; set; }
public string archive_url { get; set; }
public string downloads_url { get; set; }
public string issues_url { get; set; }
public string pulls_url { get; set; }
public string milestones_url { get; set; }
public string notifications_url { get; set; }
public string labels_url { get; set; }
public string releases_url { get; set; }
public string deployments_url { get; set; }
public DateTime created_at { get; set; }
public DateTime updated_at { get; set; }
public DateTime pushed_at { get; set; }
public string git_url { get; set; }
public string ssh_url { get; set; }
public string clone_url { get; set; }
public string svn_url { get; set; }
public string homepage { get; set; }
public int size { get; set; }
public int stargazers_count { get; set; }
public int watchers_count { get; set; }
public string language { get; set; }
public bool has_issues { get; set; }
public bool has_projects { get; set; }
public bool has_downloads { get; set; }
public bool has_wiki { get; set; }
public bool has_pages { get; set; }
public int forks_count { get; set; }
public object mirror_url { get; set; }
public bool archived { get; set; }
public bool disabled { get; set; }
public int open_issues_count { get; set; }
public License license { get; set; }
public int forks { get; set; }
public int open_issues { get; set; }
public int watchers { get; set; }
public string default_branch { get; set; }
public double score { get; set; }
}
As you see there is a bool variable called 'private' and it keeps compile error
Member modifier 'private' must precede the member type and name
My question is can I override the 'private' name or ignore the compiler error somehow?
You have to use JsonPropertyAttribute
[JsonProperty("private")]
public string whatever{get;set;} //you can give any name, it will be translated as "private"
I am trying to post a serialized object using RestSharp object is :
public class WebCRMOrganisation : IWebCRMOrganisation
{
[JsonProperty("OrganisationAddress")]
public string OrganisationAddress { get; set; }
[JsonProperty("OrganisationAlert")]
public string OrganisationAlert { get; set; }
[JsonProperty("OrganisationApprovalStatus")]
public long OrganisationApprovalStatus { get; set; }
[JsonProperty("OrganisationCity")]
public string OrganisationCity { get; set; }
[JsonProperty("OrganisationComment")]
public string OrganisationComment { get; set; }
[JsonProperty("OrganisationCompareName")]
public string OrganisationCompareName { get; set; }
[JsonProperty("OrganisationCountry")]
public string OrganisationCountry { get; set; }
[JsonProperty("OrganisationCreatedAt")]
public System.DateTimeOffset OrganisationCreatedAt { get; set; }
[JsonProperty("OrganisationCreatedBy")]
public string OrganisationCreatedBy { get; set; }
[JsonProperty("OrganisationDivisionName")]
public string OrganisationDivisionName { get; set; }
[JsonProperty("OrganisationDomain")]
public string OrganisationDomain { get; set; }
[JsonProperty("OrganisationExtraCustom1")]
public string OrganisationExtraCustom1 { get; set; }
[JsonProperty("OrganisationExtraCustom2")]
public string OrganisationExtraCustom2 { get; set; }
[JsonProperty("OrganisationExtraCustom3")]
public string OrganisationExtraCustom3 { get; set; }
[JsonProperty("OrganisationExtraCustom4")]
public string OrganisationExtraCustom4 { get; set; }
[JsonProperty("OrganisationExtraCustom5")]
public string OrganisationExtraCustom5 { get; set; }
[JsonProperty("OrganisationExtraCustom6")]
public string OrganisationExtraCustom6 { get; set; }
[JsonProperty("OrganisationExtraCustom7")]
public string OrganisationExtraCustom7 { get; set; }
[JsonProperty("OrganisationExtraCustom8")]
public string OrganisationExtraCustom8 { get; set; }
[JsonProperty("OrganisationFax")]
public string OrganisationFax { get; set; }
[JsonProperty("OrganisationGps")]
public string OrganisationGps { get; set; }
[JsonProperty("OrganisationId")]
public long OrganisationId { get; set; }
[JsonProperty("OrganisationImageFileExtension")]
public string OrganisationImageFileExtension { get; set; }
[JsonProperty("OrganisationIndustry")]
public string OrganisationIndustry { get; set; }
[JsonProperty("OrganisationLastDisplayedAt")]
public System.DateTimeOffset OrganisationLastDisplayedAt { get; set; }
[JsonProperty("OrganisationLastItemType")]
public string OrganisationLastItemType { get; set; }
[JsonProperty("OrganisationLastItemUpdatedAt")]
public System.DateTimeOffset OrganisationLastItemUpdatedAt { get; set; }
[JsonProperty("OrganisationMarketDataId")]
public string OrganisationMarketDataId { get; set; }
[JsonProperty("OrganisationName")]
public string OrganisationName { get; set; }
[JsonProperty("OrganisationNoAds")]
public bool OrganisationNoAds { get; set; }
[JsonProperty("OrganisationHistory")]
public string OrganisationHistory { get; set; }
[JsonProperty("OrganisationOutlookSync")]
public long OrganisationOutlookSync { get; set; }
[JsonProperty("OrganisationOverlayUrl")]
public string OrganisationOverlayUrl { get; set; }
[JsonProperty("OrganisationOwner")]
public long OrganisationOwner { get; set; }
[JsonProperty("OrganisationOwner2")]
public long OrganisationOwner2 { get; set; }
[JsonProperty("OrganisationPostCode")]
public string OrganisationPostCode { get; set; }
[JsonProperty("OrganisationReportTemp")]
public long OrganisationReportTemp { get; set; }
[JsonProperty("OrganisationSla")]
public long OrganisationSla { get; set; }
[JsonProperty("OrganisationState")]
public string OrganisationState { get; set; }
[JsonProperty("OrganisationStatus")]
public string OrganisationStatus { get; set; }
[JsonProperty("OrganisationTelephone")]
public string OrganisationTelephone { get; set; }
[JsonProperty("OrganisationTelephoneSearch")]
public string OrganisationTelephoneSearch { get; set; }
[JsonProperty("OrganisationTerritoryId")]
public long OrganisationTerritoryId { get; set; }
[JsonProperty("OrganisationType")]
public string OrganisationType { get; set; }
[JsonProperty("OrganisationUpdatedAt")]
public System.DateTimeOffset OrganisationUpdatedAt { get; set; }
[JsonProperty("OrganisationUpdatedBy")]
public string OrganisationUpdatedBy { get; set; }
[JsonProperty("OrganisationVatCountry")]
public string OrganisationVatCountry { get; set; }
[JsonProperty("OrganisationVatGroup")]
public string OrganisationVatGroup { get; set; }
[JsonProperty("OrganisationVatNumber")]
public string OrganisationVatNumber { get; set; }
[JsonProperty("OrganisationVatStatus")]
public string OrganisationVatStatus { get; set; }
[JsonProperty("OrganisationVatVerifiedAt")]
public System.DateTimeOffset OrganisationVatVerifiedAt { get; set; }
[JsonProperty("OrganisationWww")]
public string OrganisationWww { get; set; }
[JsonProperty("OrganisationXDate1")]
public System.DateTimeOffset OrganisationXDate1 { get; set; }
[JsonProperty("OrganisationXDate2")]
public System.DateTimeOffset OrganisationXDate2 { get; set; }
[JsonProperty("OrganisationXInt1")]
public long OrganisationXInt1 { get; set; }
[JsonProperty("OrganisationXInt2")]
public long OrganisationXInt2 { get; set; }
[JsonProperty("OrganisationXInt3")]
public long OrganisationXInt3 { get; set; }
[JsonProperty("OrganisationXInt4")]
public long OrganisationXInt4 { get; set; }
[JsonProperty("OrganisationXInt5")]
public long OrganisationXInt5 { get; set; }
[JsonProperty("OrganisationXInt6")]
public long OrganisationXInt6 { get; set; }
[JsonProperty("OrganisationXInt7")]
public long OrganisationXInt7 { get; set; }
[JsonProperty("OrganisationXInt8")]
public long OrganisationXInt8 { get; set; }
[JsonProperty("OrganisationXMemo1")]
public string OrganisationXMemo1 { get; set; }
[JsonProperty("OrganisationXMemo2")]
public string OrganisationXMemo2 { get; set; }
[JsonProperty("OrganisationXText1")]
public string OrganisationXText1 { get; set; }
[JsonProperty("OrganisationXText2")]
public string OrganisationXText2 { get; set; }
[JsonProperty("OrganisationXText3")]
public string OrganisationXText3 { get; set; }
[JsonProperty("OrganisationXText4")]
public string OrganisationXText4 { get; set; }
[JsonProperty("OrganisationXText5")]
public string OrganisationXText5 { get; set; }
[JsonProperty("OrganisationXText6")]
public string OrganisationXText6 { get; set; }
[JsonProperty("OrganisationXText7")]
public string OrganisationXText7 { get; set; }
[JsonProperty("OrganisationXText8")]
public string OrganisationXText8 { get; set; }
[JsonProperty("OrganisationPlus1")]
public string OrganisationPlus1 { get; set; }
[JsonProperty("OrganisationPlus2")]
public string OrganisationPlus2 { get; set; }
[JsonProperty("OrganisationPlus3")]
public string OrganisationPlus3 { get; set; }
[JsonProperty("OrganisationPlus4")]
public string OrganisationPlus4 { get; set; }
[JsonProperty("OrganisationPlus5")]
public string OrganisationPlus5 { get; set; }
[JsonProperty("OrganisationPlus6")]
public string OrganisationPlus6 { get; set; }
[JsonProperty("OrganisationPlus7")]
public string OrganisationPlus7 { get; set; }
[JsonProperty("OrganisationPlus8")]
public string OrganisationPlus8 { get; set; }
[JsonProperty("OrganisationPlus9")]
public string OrganisationPlus9 { get; set; }
[JsonProperty("OrganisationPlus10")]
public string OrganisationPlus10 { get; set; }
[JsonProperty("OrganisationPlus11")]
public string OrganisationPlus11 { get; set; }
[JsonProperty("OrganisationPlus12")]
public string OrganisationPlus12 { get; set; }
[JsonProperty("OrganisationPlus13")]
public string OrganisationPlus13 { get; set; }
[JsonProperty("OrganisationPlus14")]
public string OrganisationPlus14 { get; set; }
[JsonProperty("OrganisationPlus15")]
public string OrganisationPlus15 { get; set; }
[JsonProperty("OrganisationPlus16")]
public string OrganisationPlus16 { get; set; }
[JsonProperty("OrganisationPlus17")]
public string OrganisationPlus17 { get; set; }
[JsonProperty("OrganisationPlus18")]
public string OrganisationPlus18 { get; set; }
[JsonProperty("OrganisationPlus19")]
public string OrganisationPlus19 { get; set; }
[JsonProperty("OrganisationPlus20")]
public string OrganisationPlus20 { get; set; }
[JsonProperty("OrganisationCustom1")]
public string OrganisationCustom1 { get; set; }
[JsonProperty("OrganisationCustom2")]
public string OrganisationCustom2 { get; set; }
[JsonProperty("OrganisationCustom3")]
public string OrganisationCustom3 { get; set; }
[JsonProperty("OrganisationCustom4")]
public string OrganisationCustom4 { get; set; }
[JsonProperty("OrganisationCustom5")]
public string OrganisationCustom5 { get; set; }
[JsonProperty("OrganisationCustom6")]
public string OrganisationCustom6 { get; set; }
[JsonProperty("OrganisationCustom7")]
public string OrganisationCustom7 { get; set; }
[JsonProperty("OrganisationCustom8")]
public string OrganisationCustom8 { get; set; }
[JsonProperty("OrganisationCustom9")]
public string OrganisationCustom9 { get; set; }
[JsonProperty("OrganisationCustom10")]
public string OrganisationCustom10 { get; set; }
[JsonProperty("OrganisationCustom11")]
public string OrganisationCustom11 { get; set; }
[JsonProperty("OrganisationCustom12")]
public string OrganisationCustom12 { get; set; }
[JsonProperty("OrganisationCustom13")]
public string OrganisationCustom13 { get; set; }
[JsonProperty("OrganisationCustom14")]
public string OrganisationCustom14 { get; set; }
[JsonProperty("OrganisationCustom15")]
public string OrganisationCustom15 { get; set; }
[JsonProperty("OrganisationMemo")]
public string OrganisationMemo { get; set; }
}
I have tried the following code but every time I am getting bad request in response, I have checked API reference documentation JSON format is correct and I have also tried API's swagger reference I am able to use their methods fine.
var client = new RestClient("https://api.webcrm.com");
var request = new RestRequest("Organisations", Method.POST);
request.AddHeader("Accept", "application/json");
request.AddHeader("Content-Type", "application/json");
request.RequestFormat = DataFormat.Json;
request.AddParameter("application/json", JsonConvert.SerializeObject(organisation),
ParameterType.RequestBody);
WebCRMConnectivityResult c = CheckConnectivity();
request.AddHeader("Authorization", string.Format("Bearer {0}",c.AccessToken));
//request.RootElement = "organisation";
IRestResponse response = client.Execute(request);
var content = response.Content;
Can anyone please tell me what could be the issue?
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 6 years ago.
Improve this question
i have following code latitude,latitude its show 0 how get values please help.
http://private-anon-397aeee05-karhoofleetintegration.apiary-mock.com/trip?version=2&karhoo_ref=karhoo_ref
private void button1_Click(object sender, EventArgs e)
{
using (var client = new WebClient())
{
var json = client.DownloadString("http://private-anon-397aeee05-karhoofleetintegration.apiary-mock.com/trip?version=2&karhoo_ref=karhoo_ref.asmx");
var serializer = new JavaScriptSerializer();
BookingInformation bo = serializer.Deserialize<BookingInformation>(json.ToString());
}
}
public class BookingInformation
{
public string karhoo_ref { get; set; }
public string booking_id { get; set; }
public string datetime_scheduled_utc { get; set; }
public string status { get; set; }
public bool is_asap { get; set; }
public decimal latitude { get; set; }
public decimal longitude { get; set; }
}
In order to deserialize that JSON you need to provide objects that reflects the JSON itself, what you have above is nothing even close to complete. A quick JSON > C# class conversion gives this:
public class Address
{
public string display_address { get; set; }
public string building_number { get; set; }
public string street_name { get; set; }
public string city { get; set; }
public string region { get; set; }
public string postal_code { get; set; }
public string country { get; set; }
}
public class Airport
{
public string airport_code { get; set; }
public string airline_code { get; set; }
public string terminal { get; set; }
public string flight_number { get; set; }
public int meet_greet { get; set; }
}
public class FromLocation
{
public double latitude { get; set; }
public double longitude { get; set; }
public Address address { get; set; }
public string comment { get; set; }
public Airport airport { get; set; }
}
public class Address2
{
public string display_address { get; set; }
public string building_number { get; set; }
public string street_name { get; set; }
public string city { get; set; }
public string region { get; set; }
public string postal_code { get; set; }
public string country { get; set; }
}
public class ToLocation
{
public double latitude { get; set; }
public double longitude { get; set; }
public Address2 address { get; set; }
public object comment { get; set; }
public object airport { get; set; }
}
public class Passenger
{
public string first_name { get; set; }
public string last_name { get; set; }
public string phone_number { get; set; }
public bool is_primary_contact { get; set; }
}
public class Direction
{
public int kph { get; set; }
public int heading { get; set; }
}
public class Vehicle
{
public string vehicle_type { get; set; }
public string vehicle_id { get; set; }
public string vehicle_plate { get; set; }
public double latitude { get; set; }
public double longitude { get; set; }
public object eta_minutes { get; set; }
public string make { get; set; }
public string model { get; set; }
public string color { get; set; }
public string status { get; set; }
public string driver_id { get; set; }
public string driver_phone { get; set; }
public string driver_first_name { get; set; }
public string driver_last_name { get; set; }
public Direction direction { get; set; }
}
public class RootObject
{
public string karhoo_ref { get; set; }
public string booking_id { get; set; }
public int datetime_scheduled_utc { get; set; }
public string status { get; set; }
public bool is_asap { get; set; }
public bool as_directed { get; set; }
public FromLocation from_location { get; set; }
public ToLocation to_location { get; set; }
public string notes { get; set; }
public int passenger_count { get; set; }
public int luggage_count { get; set; }
public List<Passenger> passengers { get; set; }
public Vehicle vehicle { get; set; }
}
So, try and deserialize the data into those class objects. It should at least give you the data.
I am trying to execute a query using EF6 as you can see here :
List<QC> listOfJoinWithoutDSWeldAndWithoutPGZfitup =
qcs.Where(i => i.FINAL_WELD_NO == "" && i.SUBJECT == "").ToList();
So it returns 0 record.But in fact i have 16000 records that include this condition why it happens ?for proving i execute the query inside the sql as you can see :
/****** Script for SelectTopNRows command from SSMS ******/
SELECT *
FROM [PGC].[dbo].[QC] where SUBJECT='' and [FINAL WELD NO]=''
It returns 16000 records why ?
qc structure :
namespace PGZ_CO
{
using System;
using System.Collections.Generic;
public partial class QC
{
public string TP_No { get; set; }
public string UNIT { get; set; }
public string LINE_NO { get; set; }
public string JOINT_NO { get; set; }
public string SH { get; set; }
public Nullable<double> SIZE { get; set; }
public string FIT_UP_IN_NUMBER { get; set; }
public string WELDING_IN_NO { get; set; }
public string FITER_NAME { get; set; }
public string HEAT_NO1 { get; set; }
public string HEAT_NO2 { get; set; }
public string SUBJECT { get; set; }
public string INS { get; set; }
public string WELDER_NUMBER1 { get; set; }
public string REV { get; set; }
public string Type { get; set; }
public string SP_NO { get; set; }
public string MAT { get; set; }
public string NDT { get; set; }
public string PIP_CLASS { get; set; }
public string THk { get; set; }
public string SHOP_FIELD { get; set; }
public string WPS_NO { get; set; }
public Nullable<System.DateTime> FIT_UP_IN_DATE { get; set; }
public string TACK_WEL { get; set; }
public string F { get; set; }
public string ACC { get; set; }
public string SUB_CO { get; set; }
public string WELDED { get; set; }
public Nullable<System.DateTime> WELDING_IN_DATE { get; set; }
public string WELDER_NUMBER2 { get; set; }
public string WELD_ARGON1 { get; set; }
public string WELD_ARGON2 { get; set; }
public string W { get; set; }
public string REJ { get; set; }
public string SUB_CO_WELD { get; set; }
public string REMARK_FIT { get; set; }
public string REMARK_WELD { get; set; }
public string SORAT_VAZIYAT { get; set; }
public string RT { get; set; }
public string RT_REQ_NO { get; set; }
public string RT_REQ_DATE { get; set; }
public string RT_REPORT_NO { get; set; }
public string RT_REPORT_DATE { get; set; }
public string LAST_REPORT { get; set; }
public string REMARK_RT { get; set; }
public string RT_RESULT { get; set; }
public string PT { get; set; }
public string REQ_PT_NO { get; set; }
public string REQ_PT_DATE { get; set; }
public string REPORT_PT_NO { get; set; }
public string REPORT_PT__DATE { get; set; }
public string RESULT_PT { get; set; }
public string REMARK_PT { get; set; }
public string SCH { get; set; }
public string PWHT_REQ_NO { get; set; }
public string PWHT_REQ_DATE { get; set; }
public string PWHT_REPORT_NO { get; set; }
public string PWHT_REPORT_DATE { get; set; }
public string REMARK_PWHT { get; set; }
public string RESULT_PWHT { get; set; }
public string SUB_CONTRACTOR { get; set; }
public string FINAL_FIT_UP_NO { get; set; }
public string FINAL_FIT_UP_DATE { get; set; }
public string FINAL_WELD_NO { get; set; }
public string FINAL_WELD_DATE { get; set; }
public string PIP1 { get; set; }
public string PIP2 { get; set; }
public string REV_1 { get; set; }
public string WELD_REPAIR_NO { get; set; }
public string WELD_REPAIR_DATE { get; set; }
public string RESULT_REPAIR { get; set; }
public string RT_TYPE { get; set; }
public string SPEC { get; set; }
public string REMARK_WJCS { get; set; }
public bool RT_1 { get; set; }
public bool PT_1 { get; set; }
public bool PWHT_1 { get; set; }
public string PWHT { get; set; }
}
}
Best regards
Don't do the filtering on an in-memory list, it's considerably faster and more efficient to do this all in the database. For example, imagine the situation where you have 50000 records and you only need 5, it's horribly inefficient to drag all records just to get those few. So instead do this:
IEnumerable<QC> listOfJoinWithoutDSWeldAndWithoutPGZfitup =
entities.QCs.Where(i => i.FINAL_WELD_NO == "" && i.SUBJECT == "");
Note:
Querying the context directly.
Not using ToList to keep the list as queryable.
Storing the result as IEnumerable so we don't lose the link to the context.
So now you can loop through the list as before, but you can also requery the list which will in turn query the database, which is way more efficient, for example:
IEnumerable<QC> smallerList = listOfJoinWithoutDSWeldAndWithoutPGZfitup
.Where(q => q.RT_1 == true);
Merry Christmas stackies! I'm trying to parse some JSON from the Wunderground weather API and I'm running into an issue when trying to assign values to variables. Here is a link to the JSON. Just know that the class structure I'm providing is a conglomerate in order to accommodate multiple JSON return file structures. I'll give the class structre, then the call from main, and finally the actual method with the error notated. I'm working in Xamarin, formerlly MonoDevelop. Thanks for anything you can come up with!
The error reads:
Newtonsoft.Json.JsonReaderException has been thrown
"Cannot convert String to Integer: 5.0 Path
'current_observation.wind_gust_mph', line 60, position 24.
public class Wunder
{
//constructor
public Wunder ()
{
}
//JSON classes
public class HistoryResponseContainer
{
public ResponseInfo response { get; set; }
public HistoryInfo history { get; set; }
public Location location { get; set; }
public CurrentObservation current_observation { get; set; }
}
public class ResponseInfo
{
public string version { get; set; }
public string termsofService { get; set; }
public Dictionary<string, int> features { get; set; }
}
public class HistoryInfo
{
public WUDate date { get; set; }
public WUDate utcdate { get; set; }
public Observation[] observations { get; set; }
public Dailysummary[] dailysummary { get; set; }
}
public class WUDate
{
public string pretty { get; set; }
public string year { get; set; }
public string mon { get; set; }
public string mday { get; set; }
public string hour { get; set; }
public string min { get; set; }
public string tzname { get; set; }
public DateTime Value
{
get
{
int year = int.Parse(this.year);
int month = int.Parse(this.mon);
int day = int.Parse(this.mday);
int hour = int.Parse(this.hour);
int minute = int.Parse(this.min);
var kind = this.tzname == "UTC"
? DateTimeKind.Utc
: DateTimeKind.Unspecified;
return new DateTime(year, month, day, hour, minute, 0, kind);
}
}
}
public class Observation
{
public WUDate date { get; set; }
public WUDate utcdate { get; set; }
public string tempm { get; set; }
public string tempi { get; set; }
public string dewptm { get; set; }
public string dewpti { get; set; }
public string hum { get; set; }
public string wspdm { get; set; }
public string wspdi { get; set; }
public string wgustm { get; set; }
public string wgusti { get; set; }
public string wdird { get; set; }
public string wdire { get; set; }
public string vism { get; set; }
public string visi { get; set; }
public string pressurem { get; set; }
public string pressurei { get; set; }
public string windchillm { get; set; }
public string windchilli { get; set; }
public string heatindexm { get; set; }
public string heatindexi { get; set; }
public string precipm { get; set; }
public string precipi { get; set; }
public string conds { get; set; }
public string icon { get; set; }
public string fog { get; set; }
public string rain { get; set; }
public string snow { get; set; }
public string hail { get; set; }
public string thunder { get; set; }
public string tornado { get; set; }
public string metar { get; set; }
}
public class Dailysummary
{
public WUDate date { get; set; }
public string fog { get; set; }
public string rain { get; set; }
public string snow { get; set; }
public string snowfallm { get; set; }
public string snowfalli { get; set; }
public string monthtodatesnowfallm { get; set; }
public string monthtodatesnowfalli { get; set; }
public string since1julsnowfallm { get; set; }
public string since1julsnowfalli { get; set; }
public string snowdepthm { get; set; }
public string snowdepthi { get; set; }
public string hail { get; set; }
public string thunder { get; set; }
public string tornado { get; set; }
public string meantempm { get; set; }
public string meantempi { get; set; }
public string meandewptm { get; set; }
public string meandewpti { get; set; }
public string meanpressurem { get; set; }
public string meanpressurei { get; set; }
public string meanwindspdm { get; set; }
public string meanwindspdi { get; set; }
public string meanwdire { get; set; }
public string meanwdird { get; set; }
public string meanvism { get; set; }
public string meanvisi { get; set; }
public string humidity { get; set; }
public string maxtempm { get; set; }
public string maxtempi { get; set; }
public string mintempm { get; set; }
public string mintempi { get; set; }
public string maxhumidity { get; set; }
public string minhumidity { get; set; }
public string maxdewptm { get; set; }
public string maxdewpti { get; set; }
public string mindewptm { get; set; }
public string mindewpti { get; set; }
public string maxpressurem { get; set; }
public string maxpressurei { get; set; }
public string minpressurem { get; set; }
public string minpressurei { get; set; }
public string maxwspdm { get; set; }
public string maxwspdi { get; set; }
public string minwspdm { get; set; }
public string minwspdi { get; set; }
public string maxvism { get; set; }
public string maxvisi { get; set; }
public string minvism { get; set; }
public string minvisi { get; set; }
public string gdegreedays { get; set; }
public string heatingdegreedays { get; set; }
public string coolingdegreedays { get; set; }
public string precipm { get; set; }
public string precipi { get; set; }
public string precipsource { get; set; }
public string heatingdegreedaysnormal { get; set; }
public string monthtodateheatingdegreedays { get; set; }
public string monthtodateheatingdegreedaysnormal { get; set; }
public string since1sepheatingdegreedays { get; set; }
public string since1sepheatingdegreedaysnormal { get; set; }
public string since1julheatingdegreedays { get; set; }
public string since1julheatingdegreedaysnormal { get; set; }
public string coolingdegreedaysnormal { get; set; }
public string monthtodatecoolingdegreedays { get; set; }
public string monthtodatecoolingdegreedaysnormal { get; set; }
public string since1sepcoolingdegreedays { get; set; }
public string since1sepcoolingdegreedaysnormal { get; set; }
public string since1jancoolingdegreedays { get; set; }
public string since1jancoolingdegreedaysnormal { get; set; }
}
public class Station
{
public string city { get; set; }
public string state { get; set; }
public string country { get; set; }
public string icao { get; set; }
public string lat { get; set; }
public string lon { get; set; }
}
public class Airport
{
public List<Station> station { get; set; }
}
public class Station2
{
public string neighborhood { get; set; }
public string city { get; set; }
public string state { get; set; }
public string country { get; set; }
public string id { get; set; }
public double lat { get; set; }
public double lon { get; set; }
public int distance_km { get; set; }
public int distance_mi { get; set; }
}
public class Pws
{
public List<Station2> station { get; set; }
}
public class NearbyWeatherStations
{
public Airport airport { get; set; }
public Pws pws { get; set; }
}
public class Location
{
public string type { get; set; }
public string country { get; set; }
public string country_iso3166 { get; set; }
public string country_name { get; set; }
public string state { get; set; }
public string city { get; set; }
public string tz_short { get; set; }
public string tz_long { get; set; }
public string lat { get; set; }
public string lon { get; set; }
public string zip { get; set; }
public string magic { get; set; }
public string wmo { get; set; }
public string l { get; set; }
public string requesturl { get; set; }
public string wuiurl { get; set; }
public NearbyWeatherStations nearby_weather_stations { get; set; }
}
public class CurrentObservation
{
public Image image { get; set; }
public DisplayLocation display_location { get; set; }
public ObservationLocation observation_location { get; set; }
public Estimated estimated { get; set; }
public string station_id { get; set; }
public string observation_time { get; set; }
public string observation_time_rfc822 { get; set; }
public string observation_epoch { get; set; }
public string local_time_rfc822 { get; set; }
public string local_epoch { get; set; }
public string local_tz_short { get; set; }
public string local_tz_long { get; set; }
public string local_tz_offset { get; set; }
public string weather { get; set; }
public string temperature_string { get; set; }
public double temp_f { get; set; }
public double temp_c { get; set; }
public string relative_humidity { get; set; }
public string wind_string { get; set; }
public string wind_dir { get; set; }
public int wind_degrees { get; set; }
public double wind_mph { get; set; }
public int wind_gust_mph { get; set; }
public int wind_kph { get; set; }
public int wind_gust_kph { get; set; }
public string pressure_mb { get; set; }
public string pressure_in { get; set; }
public string pressure_trend { get; set; }
public string dewpoint_string { get; set; }
public int dewpoint_f { get; set; }
public int dewpoint_c { get; set; }
public string heat_index_string { get; set; }
public string heat_index_f { get; set; }
public string heat_index_c { get; set; }
public string windchill_string { get; set; }
public string windchill_f { get; set; }
public string windchill_c { get; set; }
public string feelslike_string { get; set; }
public string feelslike_f { get; set; }
public string feelslike_c { get; set; }
public string visibility_mi { get; set; }
public string visibility_km { get; set; }
public string solarradiation { get; set; }
public string UV { get; set; }
public string precip_1hr_string { get; set; }
public string precip_1hr_in { get; set; }
public string precip_1hr_metric { get; set; }
public string precip_today_string { get; set; }
public string precip_today_in { get; set; }
public string precip_today_metric { get; set; }
public string icon { get; set; }
public string icon_url { get; set; }
public string forecast_url { get; set; }
public string history_url { get; set; }
public string ob_url { get; set; }
}
public class ObservationLocation
{
public string full { get; set; }
public string city { get; set; }
public string state { get; set; }
public string country { get; set; }
public string country_iso3166 { get; set; }
public string latitude { get; set; }
public string longitude { get; set; }
public string elevation { get; set; }
}
public class Image
{
public string url { get; set; }
public string title { get; set; }
public string link { get; set; }
}
public class DisplayLocation
{
public string full { get; set; }
public string city { get; set; }
public string state { get; set; }
public string state_name { get; set; }
public string country { get; set; }
public string country_iso3166 { get; set; }
public string zip { get; set; }
public string magic { get; set; }
public string wmo { get; set; }
public string latitude { get; set; }
public string longitude { get; set; }
public string elevation { get; set; }
}
public class Estimated
{
}
And here is the call from main.
class MainClass
{
public static void Main (string[] args)
{
Wunder data = new Wunder ();
string StationID = "KCOBOULD67";
string CurrentConditions = data.GetCurrentConditions (StationID);
Console.WriteLine (CurrentConditions);
}
}
Lastly, this is the method being called. I took out my Wunderground Key. If you want an example of the return JSON, check the link at the top.
public String GetCurrentConditions(string StationID){
String url = #"http://api.wunderground.com/api/" + wundergroundkey + "/conditions/q/pws:" + StationID + ".json";
Uri uri = new Uri(url);
WebRequest webRequest = WebRequest.Create(uri);
WebResponse response = webRequest.GetResponse();
StreamReader streamReader = new StreamReader(response.GetResponseStream());
String responseData = streamReader.ReadToEnd();
var container = JsonConvert.DeserializeObject<HistoryResponseContainer> (responseData);
String stationid = container.current_observation.station_id;
String station_lat = container.current_observation.observation_location.latitude;
String station_lon = container.current_observation.observation_location.longitude;
String station_data = stationid + station_lat + station_lon;
return (station_data);
} //End GetCurrentConditions
Again, the error reads:
Newtonsoft.Json.JsonReaderException has been thrown
"Cannot convert String to Integer: 5.0 Path
'current_observation.wind_gust_mph', line 60, position 24.
You provided us a link to the following JSON:
http://api.wunderground.com/api/21fd5aec70326254/conditions/q/CA/San_Francisco.json
As you see there, the property wind_gust_mph is 0 (without the quotes, so an Integer). This JSON also works very well. But in your code you use the following JSON:
http://api.wunderground.com/api/21fd5aec70326254/conditions/q/pws:KCOBOULD67.json
And there the property wind_gust_mph is "4.0" (with the quotes, so a String). And you cannot parse a string property into an integer. Also the properties for wind_kph and wind_gust_kph are wrong, this should be either string or double:
public string wind_gust_mph { get; set; }
public double wind_kph { get; set; }
public string wind_gust_kph { get; set; }
Hope this helps and merry x-mas.