我启动了一个查询服务器对象列表的任务。
Yeet对象类结构(通过Parse Dashboard API控制台查询):
{
"results": [
{
"objectId": "6PgYUb6IUD",
"notificationText": "yeeeeet!",
"author": {
"__type": "Pointer",
"className": "_User",
"objectId": "1RtqEgy1ct"
},
"replyCount": 1,
"spice": 0,
"repliedToBy": [],
"likedBy": [],
"createdAt": "2018-06-13T06:07:09.038Z",
"updatedAt": "2018-06-13T22:27:36.636Z",
"replyCount_str": "1",
"yayeetedBy": [],
"likesCount": 0,
"likesCount_str": "0"
}
]
}
Yeet扩展了ParseObject,可以在这里查看:https://gist.github.com/SeloSlav/0b8e4be6a8d11f6f235f2820220933e7
解析调用(index.cshtml.cs):
public IEnumerable<Yeet> Reeps { get; private set; }
public async Task<JsonResult> OnPostReeps()
{
MemoryStream stream = new MemoryStream();
Request.Body.CopyTo(stream);
stream.Position = 0;
using (StreamReader reader = new StreamReader(stream))
{
string requestBody = reader.ReadToEnd();
if (requestBody.Length > 0)
{
Reeps = await GetReepsAsync(requestBody);
}
}
return new JsonResult(Reeps);
}
private async Task<IEnumerable<Yeet>> GetReepsAsync(String yeetId)
{
var query = new ParseQuery<Yeet>()
.OrderByDescending("createdAt")
.WhereEqualTo("senderParseObjectId", yeetId)
.Limit(50)
.Include("author");
Reeps = await query.FindAsync();
return Reeps;
}
然后我在我的AJAX调用(index.cshtml)中返回JSON结果:
console.log("Yeet ID: " + convoYeetId);
$.ajax({
type: "POST",
url: "Index?handler=Reeps",
headers: {
"XSRF-TOKEN": $('input:hidden[name="__RequestVerificationToken"]').val()
},
contentType: "application/json; charset=utf-8",
data: convoYeetId,
success: function (response) {
console.log(convoYeetId);
console.log(JSON.stringify(response));
...
然后将结果打印到我的控制台:
然而,没有一个对象具有objectId。
我认为JsonResult
正在解释作为通用字典类型返回的IEnumerable<Yeet>
对象,因此它生成的JSON只是一堆键值对...