をモデル化するために、私は、私は戻っています私のJSONデータを反復処理したいと、たとえば次のようになります:保存JSONのプロパティ値が
"id": 9493731,
"due_at": null,
"unlock_at": null,
"lock_at": null,
"points_possible": 1,
"grading_type": "pass_fail",
"assignment_group_id": 2645710,
"grading_standard_id": null,
"created_at": "2016-04-13T18:30:41Z",
"updated_at": "2016-08-04T05:30:03Z",
"peer_reviews": false,
"automatic_peer_reviews": false,
"position": 6,
"grade_group_students_individually": null,
"anonymous_peer_reviews": null,
"group_category_id": null
私はプロパティ名を取得し、私のモデルにそれらを保存したいですこれは次のようになります。
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CanvasAPI.Model
{
public class Assignment
{
[Key]
public int? AssignmentID { get; set; }
public int? id { get; set; }
public string name { get; set; }
public string description { get; set; }
public string created_at { get; set; }
public string updated_at { get; set; }
public string due_at { get; set; }
public string lock_at { get; set; }
public string unlock_at { get; set; }
public bool has_overrides { get; set; }
//public All_Dates[] all_dates { get; set; }
public int? course_id { get; set; }
public string html_url { get; set; }
public string submissions_download_url { get; set; }
public int? assignment_group_id { get; set; }
public string[] allowed_extensions { get; set; }
public bool turnitin_enabled { get; set; }
//public Turnitin_Settings turnitin_settings { get; set; }
public string originality_report_visibility { get; set; }
public bool s_paper_check { get; set; }
public bool internet_check { get; set; }
public bool journal_check { get; set; }
public bool exclude_biblio { get; set; }
public bool exclude_quoted { get; set; }
public string exclude_small_matches_type { get; set; }
public int? exclude_small_matches_value { get; set; }
public bool grade_group_students_individually { get; set; }
//public External_Tool_Tag_Attributes external_tool_tag_attributes { get; set; }
public bool peer_reviews { get; set; }
public bool automatic_peer_reviews { get; set; }
public int? peer_review_count { get; set; }
public string peer_reviews_assign_at { get; set; }
public bool anonymous_peer_reviews { get; set; }
public bool moderated_grading { get; set; }
public int? group_category_id { get; set; }
public int? needs_grading_count { get; set; }
//public Needs_Grading_Count_By_Section[] needs_grading_count_by_section { get; set; }
public int? position { get; set; }
public bool post_to_sis { get; set; }
public string integration_id { get; set; }
public string integration_data { get; set; }
public bool muted { get; set; }
public bool has_submitted_submissions { get; set; }
public float? points_possible { get; set; }
public string submission_types { get; set; }
public string grading_type { get; set; }
public int? grading_standard_id { get; set; }
public bool published { get; set; }
public bool unpublishable { get; set; }
public bool only_visible_to_overrides { get; set; }
public bool locked_for_user { get; set; }
//public Lock_Info lock_info { get; set; }
public string lock_explanation { get; set; }
public int? quiz_id { get; set; }
public bool anonymous_submissions { get; set; }
public string discussion_topic { get; set; }
public bool freeze_on_copy { get; set; }
public bool frozen { get; set; }
public string[] frozen_attributes { get; set; }
public string submission { get; set; }
public bool use_rubric_for_grading { get; set; }
public string rubric_settings { get; set; }
//public Rubric[] rubric { get; set; }
public int?[] assignment_visibility { get; set; }
//public Override[] overrides { get; set; }
}
私はJSONデータを反復処理し、値を取得することですが、私がモデルにデータを保存しようとする問題を抱えています。ここで
は、私がこれまで持っているものです。
Assignment assignment = new Assignment();
foreach (string myVal in name_list)
{
if (item[myVal].ToString() != string.Empty)
{
var a = "assignment" + "." + myVal;
**problem here -->** a = item[myVal].ToString();
}
}
db.Assignments.Add(assignment);db.SaveChanges();`
どのようにして変更内容を保存できるように、私は私のモデルに動的にプロパティ名と値を割り当てることができますか?
使用しないでください - newtonsoftを使用してください –