小编Joc*_*ery的帖子

InputStream到JsonObject - GSON

将结果从这个api转换为JsonObject我遇到了很多麻烦.

无论我尝试做什么,"结果"都保持为空.

  URL url = new URL(urlString);
  InputStream input = url.openStream();
  Reader reader = new InputStreamReader(in, "UTF-8");
  JsonResult result  = new Gson().fromJson(reader, JsonResult.class);
Run Code Online (Sandbox Code Playgroud)

JsonResult类

public class JsonResult {
    private String status;
    private Meta meta;
    private ArrayList<Player> players;
}

class Meta{
    private String count;
}
Run Code Online (Sandbox Code Playgroud)

JSON:

{"status":"ok","meta":{"count":12},"data":[{"nickname":"DataBase","account_id":500566109},{"nickname":"database007","account_id":514382449},{"nickname":"Database04","account_id":504367425},{"nickname":"database08","account_id":515081772},{"nickname":"database1","account_id":503282284},{"nickname":"database1221","account_id":506709044},{"nickname":"database123","account_id":508409172},{"nickname":"database1337","account_id":501661259},{"nickname":"database169","account_id":503884400},{"nickname":"database2","account_id":504337382},{"nickname":"database93","account_id":518691821},{"nickname":"databaseking66","account_id":505911069}]}
Run Code Online (Sandbox Code Playgroud)

注意:这是针对学校项目的

注2:我确实从SO检查并测试了很多其他解决方案,但没有找到或理解正确的解决方案.

编辑1:

public class JsonResult {
    @SerializedName("status")
    public String status;
    @SerializedName("meta")
    public Meta meta;
    @SerializedName("data")
    public Player[] players;
}

class Meta{
    @SerializedName("count")
    private String count;
}
Run Code Online (Sandbox Code Playgroud)

球员班

public class Player {

    private int …
Run Code Online (Sandbox Code Playgroud)

java android gson

16
推荐指数
1
解决办法
2万
查看次数

是否真的需要MySQL查询中的表和列的引号?

我有一个关于mysql查询的简短问题.

什么是正确的?

SELECT * FROM Persons WHERE Year='1965'
Run Code Online (Sandbox Code Playgroud)

要么

SELECT * FROM `Persons` WHERE `Year` = '1965'
Run Code Online (Sandbox Code Playgroud)

这是个人选择还是这是真正的错误?

php mysql

10
推荐指数
3
解决办法
779
查看次数

使用 FakeItEasy 测试 ILogger

我正在为自己做一个有趣的项目来学习 blazor、很多核心概念和一般实践。

我正在尝试为 FakeItEasy 实现记录器扩展,以更轻松地测试 Microsoft 的 ILogger。基于https://dev.azure.com/BrideButler/Bride%20Butler%20Open%20Source/_git/FakeItEasy.DotnetCore.LoggerExtensions?path=%2FFakeItEasy.DotnetCore.LoggerExtensions%2FLoggerExtensions.cs但现在尝试让它工作对于.NET 5。现在这FormattedLogValues是内部的,这段代码不再起作用。

目标是在我的测试中拥有类似的东西(而不是使用 Moq), _logger.VerifyLog(LogLevel.Information, "Get Weather Called").MustHaveHappenedOnceExactly(); 或者A.CallTo(() => _logger.Log(LogLevel.Information, "Get Weather Called").MustHaveHappenedOnceExactly();它不必有语法糖,但我想让它与 FakeItEasy 而不是 Moq 一起使用。

以下是所有涉及的代码。当然,我在第一行Microsoft.Extensions.Logging.ILogger.Log1[System.Object] vsMicrosoft.Extensions.Logging.ILogger 1[Server.Controllers.WeatherForecastController].Log1[Microsoft.Extensions.Logging.FormattedLogValues]` 中看到了一些差异,但我不知道如何“修复”这个问题,因为我不完全理解出了什么问题。

我的问题显然是,我应该做什么来解决它,但也很好奇我缺少什么部分。

我的错误如下:

  Assertion failed for the following call:
        Microsoft.Extensions.Logging.ILogger.Log`1[System.Object]
        (
            logLevel: Information,
            eventId: <Ignored>, 
            state: <e => e.ToString().Contains(value(Server.Tests.Extensions.LoggerExtensions+<>c__DisplayClass2_0`1[Server.Controllers.WeatherForecastController]).message)>,
            exception: <Ignored>, 
            formatter: <Ignored>
        )
      Expected to find it once exactly but didn't find it among the calls:
        1: Microsoft.Extensions.Logging.ILogger`1[Server.Controllers.WeatherForecastController].Log`1[Microsoft.Extensions.Logging.FormattedLogValues]
        (
            logLevel: Information, …
Run Code Online (Sandbox Code Playgroud)

c# fakeiteasy ilogger

8
推荐指数
2
解决办法
3768
查看次数

从powershell执行msbuild任务

我关注此博客:http://sedodream.com/2010/04/26/ConfigTransformationsOutsideOfWebAppBuilds.aspx

它在这个问题中被链接为答案:Web.Config在Microsoft MSBuild之外进行转换?

每个步骤都按照描述工作,但我想从powershell脚本调用转换.我想在powershell中执行此命令msbuild trans.proj /t:Demo 我发现一些论坛说我应该使用invoke-expression

当我尝试时,我得到这个错误

电源外壳:

Invoke-Expression $msbuild transformCommand.proj /t:Demo
Run Code Online (Sandbox Code Playgroud)

结果

Invoke-Expression : Cannot bind argument to parameter 'Command' because it is null.
At D:/Somewhere
+ Invoke-Expression <<<<  $msbuild transformCommand.proj /t:Demo
    + CategoryInfo          : InvalidData: (:) [Invoke-Expression], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.InvokeExpre
   ssionCommand
Run Code Online (Sandbox Code Playgroud)

我也尝试过:

Invoke-Expression msbuild transformCommand.proj /t:Demo
Run Code Online (Sandbox Code Playgroud)

结果

 D:\Somewhere
Invoke-Expression : A positional parameter cannot be found that accepts argument 'transformCommand.proj'.
At D:\Redgate\Communited.Timeblockr.Api\PreDeploy1.ps1:14 char:18
+ Invoke-Expression <<<<  msbuild transformCommand.proj /t:Demo …
Run Code Online (Sandbox Code Playgroud)

msbuild powershell-2.0

5
推荐指数
1
解决办法
2万
查看次数

多重可选枚举

我正在研究一种工具,这样我就可以在游戏中保持井井有条.

这是我的班级:

//The item
public class Item
{
    public int Id { get; set; }
    public string Name { get; set; }
    public decimal Value { get; set; }
    public ItemLabel Label { get; set; }
    public ItemType Type { get; set; }
    public ItemTradeType TradeType { get; set; }
    public Trade Trade { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

Label / Type / TradeType / Trade是枚举.

视图:

@model EveMonitorV2.Models.Item

@{
    ViewBag.Title = "AddItem";
}

<h2>AddItem</h2>

@using (Html.BeginForm())
{
    @Html.AntiForgeryToken() …
Run Code Online (Sandbox Code Playgroud)

razor asp.net-mvc-4

3
推荐指数
1
解决办法
2847
查看次数

Java无法找到Main类

我有一个简短的问题,我在java中写了这个.旧代码:

   class apples{
        public static void main(String args[]){
            System.out.println("hello Youtube");
        }
    }
Run Code Online (Sandbox Code Playgroud)

新代码

public class apples{
        public static void main(String args[]){
            System.out.println("hello Youtube");
        }
    }
Run Code Online (Sandbox Code Playgroud)

Eclipse给我这个错误:

错误:无法找到或加载主类苹果

我究竟做错了什么?我正在看Bucky的这个教程:Youtube

第二个问题:

在教程中有类似自动完成的内容.我怎么能在日食中打开它?

修复:打开一个文件而不是类谢谢你的帮助!

java

1
推荐指数
1
解决办法
2762
查看次数

Bootstrap Dialog (nakupanda) 获取表单值 [JSFiddle]

我很难从我的表单中获取值。

我正在使用 nakupanda 的引导对话框(http://nakupanda.github.io/bootstrap3-dialog/

对话框(在全日历选择功能中)

http://arshaw.com/fullcalendar/docs/selection/select_callback/

var form = $('#createEventForm').html();
    BootstrapDialog.show({
    message: form,
         buttons: [{
                label: 'Enkel rooster event',
                action: function(dialogItself){
                    console.log('enkel - create')
                    dialogItself.close();                           
                }
            },{
                label: 'Herhalend rooster event (elke dag)',
                action: function(dialogItself){
                    console.log('meer - create')
                    dialogItself.close();
                }
            },{
                label: 'Close',
                action: function(dialogItself){
                    console.log(dialogItself);
                     alert('The content of the dialog is: ' + dialogItself.getModal().html());
            }
        }]
    });
Run Code Online (Sandbox Code Playgroud)

html表单

<form id="createEventForm">
    <label>Klantnaam</label>
    <input type="text" id="titleDrop" />
    <br/>
    <label>Beschrijving</label>
    <input type="text" id="descriptionDrop" />
</form>
Run Code Online (Sandbox Code Playgroud)

当有人单击按钮时,我不知道如何从表单输入中检索数据。I've tried $(titleDrop).val()和 …

javascript jquery twitter-bootstrap

1
推荐指数
1
解决办法
4341
查看次数

需要解释这个javascript

我对我发现和使用的这个脚本有疑问.它有效,但我不明白为什么.练习是使用从-50到50的随机数列表.下面的函数使用Math.floor(Math.random() *(我不理解的部分).

如果我把这个计算放在谷歌我得到答案151,Math.random()*151并没有从-50到50.

有人可以给我一个关于这个功能的明确解释,因为我确信我错过了一些东西.

这个脚本有效,但我只想清楚解释如何

for (i = 0; i <= 100; i++)
{
    Rnumber[i] = randomFromTo(-50,50);
}

function randomFromTo(from, to)
{
    return Math.floor(Math.random() * (to - from + 1) + from);
}
Run Code Online (Sandbox Code Playgroud)

javascript math

0
推荐指数
1
解决办法
148
查看次数

更新字典C#

我在更新字典方面遇到了问题

我也读过很多关于这个说法的话题(例如链接)

ExampleDict[key] = value;
Run Code Online (Sandbox Code Playgroud)

我试着用自己的代码:

模型:

  public Dictionary<int, string> Info { get; set; }
  public Dictionary<int, string> GetInfo(int id)
    {
        Info = new Dictionary<int, string>();

        var game = db.Games.Find(id);

        var playerOne = db.Players.Find(game.PlayerOneId);
        var playerTwo = db.Players.Find(game.PlayerTwoId);
        var PlayerOneName = playerOne.Nickname;
        var PlayerTwoName = playerTwo.Nickname;
        int scoreOne = CountScorePlayerOne();
        int scoreTwo = CountScorePlayerTwo();


        // old aproach:
        Info.Add(scoreOne, PlayerOneName);
        Info.Add(scoreTwo, PlayerTwoName);

        //new approach
        Info[key] = scoreOne;

        return Info;


    }
Run Code Online (Sandbox Code Playgroud)

错误

当前上下文中不存在名称"key"

注意:我是学生,这是一个学校项目.

关于我做错了什么的任何想法?

通过Jon Senchyna的代码示例解决,谢谢!

c# asp.net-mvc-4

-1
推荐指数
1
解决办法
622
查看次数