我有一个看起来像这样的json文件:
[["{\"id\":1474721566304,\"name\":\"GGG\",\"brand\":\"GG\",\"price\":\"3\"}"],["{\"id\":1474721570904,\"name\":\"GGGH\",\"brand\":\"GGH\",\"price\":\"4\"}"],["{\"id\":1474721574188,\"name\":\"GGGH\",\"brand\":\"GGHH\",\"price\":\"5\"}"]]
Run Code Online (Sandbox Code Playgroud)
我想要做的是从它删除它的记录id.为此,我有以下PHP代码:
<?php
$string = file_get_contents("products.json");
$json_a = json_decode($string, true); //turning JSON-string into an array containing JSON-strings
$arr = array();
foreach ($json_a as $key) {
array_push($arr,json_decode($key[0],true)); //and here you turning each of the JSON-strings into objects themselves
}
$data= $_GET['data'];
$i=0;
foreach($arr as $element) {
if($data == $element["id"]){
unset($arr[$i]);//removing the product by ID
}
$i++;
}
var_dump($arr);
$arr2 = array();
foreach ($arr as $key) {//trying to make it look like the original json.
array_push($arr2,json_decode($key[0],true));
}
//var_dump($arr2);
echo …Run Code Online (Sandbox Code Playgroud) 在我的电子表格中,我有一个正在运行的脚本,该脚本将该getLastRow()函数用作其逻辑的重要组成部分。
自从我在其中一列中应用了数组公式后,该getLastRow()函数就无法正常工作。即使其他列中没有其他值,数组公式似乎一直“应用”到工作表的底部,因此getLastRow()返回有数组公式的最后一行,而不是实际的非- 空行。
编写一个检查哪些单元格为空的慢速函数对我来说不是一个选择,因为脚本在运行这样的事情时会用完(它有数万行)。
有没有人对解决方法有任何建议?
这是ARRAYFORMULA:
=ArrayFormula(IF(A2:A="",,WEEKNUM(A2:A, 2)))
Run Code Online (Sandbox Code Playgroud) 当我尝试使用 foreach 遍历我的 JSON 对象时出现此错误。有人可以帮忙吗?
这是我的JS:
function dateTimeChecker() {
$.ajax({
"url": 'get-booked.php',
"method": "get",
"dataType": "text",
"cache": false
}).done(function(jBooked) {
var jBookedDates=JSON.parse(jBooked);
console.log(jBookedDates);
jBookedDates.forEach(function(jB){
if (jB=="11/01/2016") {console.log("works");}else{console.log("doesn't");}
})
});
}
Run Code Online (Sandbox Code Playgroud)
这是有问题的对象:
另外,我想知道如果有人愿意解释,我该如何迭代这个对象。:)
目前我有一个使用datepicker. 我想知道如何禁用单击该字段时弹出的 datepicker callendar,因为在我的页面上,我希望日期选项仅在某些条件下可用。
<input id="date" type="text " class="form-control datepicker" name="date" value="Click to select date">
Run Code Online (Sandbox Code Playgroud)
我试过:
$("#date").datepicker('disable');
Run Code Online (Sandbox Code Playgroud)
与 :
$( "#date" ).datepicker( "disabled", true );
Run Code Online (Sandbox Code Playgroud)
没有一个工作。
我有一个bootstrap形式的信息,我使用ajax调用从中保存到json文件.
我的问题是当我按下提交按钮时,页面似乎在调用后刷新(在单击提交按钮后执行),这是我一定要避免的.
我试图调查这个问题,但是我的知识不足以解决这个问题,因为我对这些概念没有深入的了解.
这是我的BS表格:
<form class="form-horizontal">
<div class="form-group">
<label class="control-label col-sm-2" for="name">Full Name:</label>
<div class="col-sm-2">
<input type="name" class="form-control" id="nameFull">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="phone">Phone:</label>
<div class="col-sm-2">
<input type="phone" class="form-control" id="phoneApp">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="email">Email:</label>
<div class="col-sm-2">
<input type="email" class="form-control" id="emailApp">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="date">Date:</label>
<div class="col-sm-2">
<input type="date" class="form-control" id="date">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="text">Hour:</label>
<div class="col-sm-2">
<select class="form-control" id="time">
<option value="Time" class="">Time</option>
<option value="10am" class="">10:00-10:30</option> …Run Code Online (Sandbox Code Playgroud) 我在视图中有以下代码:
@{
var i = 0;
var posts = Session["num"] as List<class_project.Models.Post>;
if (posts != null)
{
foreach (object item in posts)
{
<p>@item</p>
}
}
}
Run Code Online (Sandbox Code Playgroud)
因此我得到了:几个class_project.Models.Post字符串.
如何显示我的实际对象呢?我尝试使用item.something,这实际上并不起作用.
在var workrolesusersdetailsQuery后过滤我得到一个三个int?ID 的列表.在foreach循环中,我只是尝试删除id不等于上述id的所有对象.结果它删除了所有对象.有趣的是,如果我更换了!=它==然后它正常工作.
我只是看不出我做错了什么,所以,拜托,有人可以帮忙吗?
var workrolesusersdetailsQuery = db.WorkRolesUsersDetails
.Where(m => m.UserDetailsId == currentUserId && m.isActive == true)
.Select(m => m.WorkRoleId).ToList();//select only thw workroleid column
foreach (var wr in workrolesusersdetailsQuery)
{
var temp = wr;
WorkRolesQuery.RemoveAll((x) => x.WorkRoleId != wr);
}
Run Code Online (Sandbox Code Playgroud) 我有一个来自php的字符串,看起来完全像: "[{"id":"0","noteText":"Noteeeeeeee","date":"1232131","author":"John","authorId":"1"},{"id":"1","noteText":"Noteeeeeeee","date":"1232131","author":"Rob","authorId":"1"}]"
然后在我的onCreate中mainActiviry.java我达到了这一点:
String json = allNotes;
//System.out.println("String to Json Array Stmt");
JsonParser parser = new JsonParser();
JsonElement notes = parser.parse(allNotes);
JsonArray notesArr = notes.getAsJsonArray();
Run Code Online (Sandbox Code Playgroud)
我的目标是将json字符串解析为json对象数组,然后遍历它并将其提供给a ListView.问题是我无法到达那里,因为我没有绕过这个jsonArray.我的java知识太有限了,所以其他问题对我没什么帮助.
有人可以帮帮忙吗?
ps我正在使用gson
javascript ×3
json ×3
ajax ×2
asp.net-mvc ×2
c# ×2
jquery ×2
php ×2
android ×1
arrays ×1
datepicker ×1
gson ×1
java ×1
linq ×1