注意:我也使用here的模板和AspNetBoilerplate标签帮助程序,因此bc-
属性和form-group
标签是有效的。
我正在尝试将模型发布到我的一个应用程序服务中。但是我收到以下错误
”验证期间检测到以下错误。 ↵-无法反序列化当前JSON对象(例如{“ name”:“ value”})为类型'System.Collections.Generic.IList`1 [App.Stores.StoreWalk.Dtos.CreateOrEditStoreWalkCategoryDto]',因为该类型需要JSON数组(例如[1,2,3])正确反序列化。 ↵要解决此错误,请将JSON更改为JSON数组(例如[1,2,3])或更改反序列化类型,使其成为常规.NET类型(例如,不是整数之类的原始类型,而不是一个集合类型) (例如数组或列表),可以从JSON对象反序列化。还可以将JsonObjectAttribute添加到类型中,以强制其从JSON对象反序列化。 ↵路径'categories.0',第1行,位置84。 ↵“消息:“您的请求无效!” validationErrors:[{...}] proto :对象
我了解错误的含义,但我不知道如何解决我的代码。
在2条建议中,To fix this error either change the JSON to a JSON array (e.g. [1,2,3])
是我必须采取的方法。
可能不适合我,但是我在玩我的代码,并注意到从@i
属性中删除@j
和name
时发现可以成功发布,但是单选按钮丢失了所有功能(由于命名冲突,单击第二行会更改第一行),而且,我认为需要索引来保持它们唯一(我仍在学习,如果我写错了,请纠正我)。
即时通讯发回的json字符串是通过调用$('form[name=StoreWalkForm]').serializeFormToObject()
创建的,该字符串如下所示,并使用Mecons
$.fn.serializeFormToObject = function() {
var $form = $(this);
var fields = $form.find('[disabled]');
fields.prop('disabled', false);
var json = $form.serializeJSON();
fields.prop('disabled', true);
return json;
};
{
"version": "2",
"department": {
"id": "8",
"name": "ISF"
},
"store": "001",
"categories": {
"0": {
"category": {
"id": "4"
},
"questions": {
"0": {
"question": {
"question": "SIGNAGE",
"id": "233"
},
"answer": {
"boolValue": "false",
"comments": "1"
}
},
"1": {
"question": {
"question": "PARKING LOT BLACKTOP",
"id": "234"
},
"answer": {
"boolValue": "true",
"comments": "2"
}
}
}
}
},
"comments": "123",
"signature": ""
}
public class CreateOrEditStoreWalkDto : EntityDto<int?>
{
[Required]
public string Store { get; set; }
public string Comments { get; set; }
public byte[] Signature { get; set; }
public int Version { get; set; }
public DepartmentsDto Department { get; set; }
public IList<CreateOrEditStoreWalkCategoryDto> Categories { get; set; } = new List<CreateOrEditStoreWalkCategoryDto>();
}
public class CreateOrEditStoreWalkCategoryDto
{
public CategoriesDto Category { get; set; }
public IList<CreateOrEditStoreWalkQuestionDto> Questions { get; set; } = new List<CreateOrEditStoreWalkQuestionDto>();
}
public class CreateOrEditStoreWalkQuestionDto
{
public QuestionsDto Question { get; set; }
public AnswersDto Answer { get; set; }
}
CSHtml
<form name="StoreWalkInformationsForm" role="form" enctype="multipart/form-data" novalidate class="form-validation">
@if (Model.IsEditMode)
{
<input type="hidden" name="id" value="@Model.StoreWalk.Id" />
}
<input type="hidden" name="version" value="@Model.StoreWalk.Version" />
<input type="hidden" name="department[id]" value="@Model.StoreWalk.Department.Id" />
<input type="hidden" name="department[name]" value="@Model.StoreWalk.Department.Name" />
<form-group>
<select id="StoreWalk_Store" name="store" bc-label="@L("Store")" required="required" bc-required="true" bc-validation="true" value="@Model.StoreWalk.Store" maxlength="@App.Stores.StoreWalk.EntriesConsts.MaxStoreLength" minlength="@App.Stores.StoreWalk.EntriesConsts.MinStoreLength">
@if (!Model.IsEditMode)
{
<option value="" selected="selected"></option>
}
</select>
</form-group>
<br /><br />
@for (var i = 0; i < Model.StoreWalk.Categories.Count; i++)
{
<h5 class="m--font-primary">@Model.StoreWalk.Categories[i].Category.Name</h5>
<input type="hidden" name="categories[@i][category][id]" value="@Model.StoreWalk.Categories[i].Category.Id" />
<table bc-responsive="true">
<thead>
<tr>
<th>#</th>
<th scope="col">Question</th>
<th scope="col"></th>
<th scope="col">Comments</th>
</tr>
</thead>
<tbody>
@*@for (var j = 0; j < Model.StoreWalk.Categories[i].Questions.Count; j++)*@
@for (var j = 0; j < 2; j++)
{
<tr>
<td>@(q.Next()).</td>
<td scope="row">
<form-group>
<input type="hidden" name="categories[@i][questions][@j][question][question]" value="@Model.StoreWalk.Categories[i].Questions[j].Question.Question" bc-label="@Model.StoreWalk.Categories[i].Questions[j].Question.Question" />
<input type="hidden" name="categories[@i][questions][@j][question][id]" value="@Model.StoreWalk.Categories[i].Questions[j].Question.Id" />
<br />
@Html.TextBoxFor(m => m.StoreWalk.Categories[i].Questions[j].S3Files, new { type = "file", multiple = "multiple" })
</form-group>
</td>
<td>
<form-group>
<radio-list bc-required="true" bc-validation="true" id="categories[@i][questions][@j][answer][boolValue]">
<input type="radio" name="categories[@i][questions][@j][answer][boolValue]" value="true" bc-label="@L("Yes")" required="required" />
<input type="radio" name="categories[@i][questions][@j][answer][boolValue]" value="false" bc-label="@L("No")" required="required" />
</radio-list>
</form-group>
</td>
<td>
<form-group>
<textarea name="categories[@i][questions][@j][answer][comments]" rows="3">@Model.StoreWalk.Categories[i].Questions[j].Answer.Comments</textarea>
</form-group>
</td>
</tr>
}
</tbody>
</table>
}
<form-group>
<textarea class="form-control" id="StoreWalk_Comments" type="text" name="comments" bc-label="@L("Comments")" rows="4">@Model.StoreWalk.Comments</textarea>
</form-group>
<form-group>
<label for="signature">@L("Signature")</label>
@Html.Partial("~/Areas/Shared/Views/Shared/SignaturePad/Edit.cshtml", new SignaturePadModel()
{
Id = "signature",
Data = Model.StoreWalk.Signature,
FooterText = L("Signature"),
Required = true
})
</form-group>
</form>
答案 0 :(得分:1)
将java.lang.RuntimeException:
at android.view.DisplayListCanvas.throwIfCannotDraw (DisplayListCanvas.java:260)
at android.graphics.Canvas.drawBitmap (Canvas.java:1420)
at android.graphics.drawable.BitmapDrawable.draw (BitmapDrawable.java:545)
at android.widget.ImageView.onDraw (ImageView.java:1286)
at android.view.View.draw (View.java:18394)
at android.view.View.updateDisplayListIfDirty (View.java:17372)
at android.view.View.draw (View.java:18156)
at android.view.ViewGroup.drawChild (ViewGroup.java:3969)
at android.view.ViewGroup.dispatchDraw (ViewGroup.java:3755)
at android.support.constraint.ConstraintLayout.dispatchDraw (ConstraintLayout.java:2023)
at android.view.View.draw (View.java:18397)
at android.view.View.updateDisplayListIfDirty (View.java:17372)
at android.view.View.draw (View.java:18156)
at android.view.ViewGroup.drawChild (ViewGroup.java:3969)
at android.view.ViewGroup.dispatchDraw (ViewGroup.java:3755)
at android.view.View.updateDisplayListIfDirty (View.java:17367)
at android.view.View.draw (View.java:18156)
at android.view.ViewGroup.drawChild (ViewGroup.java:3969)
at android.view.ViewGroup.dispatchDraw (ViewGroup.java:3755)
at android.view.View.updateDisplayListIfDirty (View.java:17367)
at android.view.View.draw (View.java:18156)
at android.view.ViewGroup.drawChild (ViewGroup.java:3969)
at android.view.ViewGroup.dispatchDraw (ViewGroup.java:3755)
at android.view.View.updateDisplayListIfDirty (View.java:17367)
at android.view.View.draw (View.java:18156)
at android.view.ViewGroup.drawChild (ViewGroup.java:3969)
at android.view.ViewGroup.dispatchDraw (ViewGroup.java:3755)
at android.view.View.updateDisplayListIfDirty (View.java:17367)
at android.view.View.draw (View.java:18156)
at android.view.ViewGroup.drawChild (ViewGroup.java:3969)
at android.view.ViewGroup.dispatchDraw (ViewGroup.java:3755)
at android.view.View.draw (View.java:18397)
at com.android.internal.policy.DecorView.draw (DecorView.java:967)
at android.view.View.updateDisplayListIfDirty (View.java:17372)
at android.view.ThreadedRenderer.updateViewTreeDisplayList (ThreadedRenderer.java:722)
at android.view.ThreadedRenderer.updateRootDisplayList (ThreadedRenderer.java:728)
at android.view.ThreadedRenderer.draw (ThreadedRenderer.java:836)
at android.view.ViewRootImpl.draw (ViewRootImpl.java:3181)
at android.view.ViewRootImpl.performDraw (ViewRootImpl.java:2977)
at android.view.ViewRootImpl.performTraversals (ViewRootImpl.java:2565)
at android.view.ViewRootImpl.doTraversal (ViewRootImpl.java:1550)
at android.view.ViewRootImpl$TraversalRunnable.run (ViewRootImpl.java:7189)
at android.view.Choreographer$CallbackRecord.run (Choreographer.java:959)
at android.view.Choreographer.doCallbacks (Choreographer.java:734)
at android.view.Choreographer.doFrame (Choreographer.java:670)
at android.view.Choreographer$FrameDisplayEventReceiver.run (Choreographer.java:945)
at android.os.Handler.handleCallback (Handler.java:751)
at android.os.Handler.dispatchMessage (Handler.java:95)
at android.os.Looper.loop (Looper.java:154)
at android.app.ActivityThread.main (ActivityThread.java:6776)
at java.lang.reflect.Method.invoke (Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1520)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1410)
传递到<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".KnowICLHomePage"
android:background="@drawable/customborder">
<android.support.constraint.ConstraintLayout
android:id="@+id/constraintLayout2"
android:layout_width="0dp"
android:layout_height="380dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="12dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:paddingLeft="30dp"
android:paddingRight="30dp"
android:paddingBottom="20dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imageView5">
<ImageButton
android:id="@+id/button_about_icl"
style="@android:style/Widget.DeviceDefault.ImageButton"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="32dp"
android:background="@null"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/about_us_button" />
<ImageButton
android:id="@+id/button_our_products"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginStart="40dp"
android:layout_marginLeft="40dp"
android:layout_marginTop="32dp"
android:background="@null"
app:layout_constraintStart_toEndOf="@+id/button_about_icl"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/our_products_button" />
<ImageButton
android:id="@+id/button_fund_performance"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="20dp"
android:background="@null"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView_button_about_icl"
app:srcCompat="@drawable/fund_performance_button" />
<ImageButton
android:id="@+id/button_how_to_invest"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginStart="40dp"
android:layout_marginLeft="40dp"
android:layout_marginTop="20dp"
android:background="@null"
app:layout_constraintStart_toEndOf="@+id/button_fund_performance"
app:layout_constraintTop_toBottomOf="@+id/textView_button_our_products"
app:srcCompat="@drawable/how_to_invest_button" />
<TextView
android:id="@+id/textView_button_about_icl"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:text="@string/knowicl_about_icl"
android:textAlignment="center"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/button_about_icl" />
<TextView
android:id="@+id/textView_button_our_products"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_marginStart="40dp"
android:layout_marginLeft="40dp"
android:text="@string/knowicl_our_products"
android:textAlignment="center"
app:layout_constraintStart_toEndOf="@+id/textView_button_about_icl"
app:layout_constraintTop_toBottomOf="@+id/button_our_products" />
<TextView
android:id="@+id/textView_button_fund_performance"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:text="@string/knowicl_fund_performance"
android:textAlignment="center"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/button_fund_performance" />
<TextView
android:id="@+id/textView_button_how_to_invest"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_marginStart="40dp"
android:layout_marginLeft="40dp"
android:text="@string/knowicl_how_to_invest"
android:textAlignment="center"
app:layout_constraintStart_toEndOf="@+id/textView_button_fund_performance"
app:layout_constraintTop_toBottomOf="@+id/button_how_to_invest" />
</android.support.constraint.ConstraintLayout>
<ImageButton
android:id="@+id/button_call_now_for_details"
android:layout_width="40dp"
android:layout_height="45dp"
android:layout_marginStart="60dp"
android:layout_marginLeft="60dp"
android:layout_marginBottom="30dp"
android:background="@null"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:srcCompat="@drawable/call_now_button" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:layout_marginLeft="32dp"
android:text="@string/knowicl_button_call_now_for_details"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/button_call_now_for_details" />
<ImageButton
android:id="@+id/button_visit_us"
android:layout_width="40dp"
android:layout_height="45dp"
android:layout_marginEnd="60dp"
android:layout_marginRight="60dp"
android:layout_marginBottom="30dp"
android:background="@null"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:srcCompat="@drawable/find_us_on_map" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="32dp"
android:layout_marginRight="32dp"
android:text="@string/knowicl_visit_our_office"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/button_visit_us" />
<ImageView
android:id="@+id/imageView5"
android:layout_width="120dp"
android:layout_height="71dp"
android:layout_marginStart="4dp"
android:layout_marginLeft="4dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.505"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/icl_logo" />
</android.support.constraint.ConstraintLayout>
。
{useIntKeysAsArrayIndex: true}
来自链接到问题的https://github.com/marioizquierdo/jquery.serializeJSON:
使用整数键作为数组索引
$form.serializeJSON()
$.fn.serializeFormToObject = function() { var $form = $(this); var fields = $form.find('[disabled]'); fields.prop('disabled', false); // var json = $form.serializeJSON(); var json = $form.serializeJSON({useIntKeysAsArrayIndex: true}); fields.prop('disabled', true); return json; };
<form> <input type="text" name="arr[0]" value="foo"/> <input type="text" name="arr[1]" value="var"/> <input type="text" name="arr[5]" value="inn"/> </form>