我有一个PHP代码,需要将DB表数据编码为json.所以我使用了json_encode().
我使用这里给出的表格 - http://www.geekality.net/2011/08/21/country-names-continent-names-and-iso-3166-codes-for-mysql/
对于不同的输入,此代码的行为似乎不同.
查询 - $query = "SELECT * FROM countries ";不返回任何json值.
查询 - $query = "SELECT * FROM countries where continent_code='AS'";正确返回json值.
然而,$query = "SELECT * FROM countries where continent_code='EU'";也没有返回任何东西.
类似'NA','AF'不起作用,其他人工作完美.
我对PHP的json_encode的这种行为很奇怪.
这是我的代码.
<?php
$con=mysqli_connect('localhost','xxxx','xxxxx','joomla30');
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM countries where continent_code='EU'") or die (mysqli_error($con));
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
$orders[] = array(
'CountryCode' => $row['code'], …Run Code Online (Sandbox Code Playgroud) 只是想知道我们是否可以在不编写自定义比较器类的情况下使用 Java 8 根据重复数字的频率对列表进行排序。
我需要根据给定的整数的频率,然后按自然数字顺序对给定的整数进行排序。
我在Comparator.naturalOrder()处遇到错误;
这是我尝试过的代码:
Integer[] given = new Integer[]{0,0,1,22,11,22,22,11,44,555,55,66,77,88,99};
List<Integer> intList = Arrays.asList(given);
Map<Integer, Long> frequencyMap = intList.stream().collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
List<Integer> newList = intList.stream().sorted(Comparator.comparing(frequencyMap::get).thenComparing(Comparator.naturalOrder())).collect(Collectors.toList());
System.out.println(newList.toString());
Run Code Online (Sandbox Code Playgroud)
预期的输出是
[1, 44, 55, 66, 77, 88, 99, 555, 0, 0, 11, 11, 22, 22, 22]
Run Code Online (Sandbox Code Playgroud)
PS:在第一行使用数组以避免在多行中使用 list.add() 并清楚理解。