小编The*_*tar的帖子

使用Java中的GSON解析复杂的Json对象

我有一个非常长的JSON来解析Gson,但为了简洁起见,我将它修剪为这个例子:

{
 "volumes": [
  {
   "status": "available", 
   "managed": true, 
   "name": "va_85621143-1133-412f-83b4-57a01a552638_", 
   "support": {
    "status": "supported"
   }, 
   "storage_pool": "pfm9253_pfm9254_new", 
   "id": "afb8e294-6188-4907-9f6f-963c7623cecb", 
   "size": 9
  }, 
  {
   "status": "in-use", 
   "managed": false, 
   "name": "bt_newd20", 
   "support": {
    "status": "not_supported", 
    "reasons": [
     "This volume is not a candidate for management because it is already attached to a virtual machine.  To manage this volume with PowerVC, select the virtual machine to which the volume is attached for management. The attached volume will be automatically included for management." …
Run Code Online (Sandbox Code Playgroud)

java serialization json gson

25
推荐指数
1
解决办法
4万
查看次数

逐行在属性文件中添加注释

这是我想在属性文件中执行的操作

#Comments about key Value pair 1
Key_1=value_1


#Comments about key Value pair 2
Key_2=value_2

#Comments about key Value pair 3
Key_3=value_3
Run Code Online (Sandbox Code Playgroud)

现在我能用我的文件做的是

#OMG, It works!
#Mon Oct 14 01:22:10 IST 2013
Key_1=Value_1
Key_2=Value_2
Run Code Online (Sandbox Code Playgroud)

有没有办法做这样的事情

java properties

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

在shell中逐列解析Json数据

当我运行命令时,我得到这样的响应

{

    "status": "available",
    "managed": true,
    "name":vdisk7,
    "support":{
    "status": "supported"
    },
    "storage_pool": "pfm9253_pfm9254_new",
    "id": "ff10abad"-2bf-4ef3-9038-9ae7f18ea77c",
    "size":100
},
Run Code Online (Sandbox Code Playgroud)

和数百种这种类型的列表或词典我想要一个做这种事情的命令

if name = "something", 
    get the id
Run Code Online (Sandbox Code Playgroud)

任何可以帮助我学习这类命令的链接都将受到高度赞赏

我试过了

awk'{if($ 2 =="something")打印$ 0;}'

但我认为响应是在Json中,因此colum明智的awk格式化不起作用.

此外,它只是我需要运行的一个命令,所以我不想使用任何外部库.

bash shell awk

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

使用HTTP Commons Client进行基本身份验证

我正在寻找此链接,我正在尝试向服务器发送请求

http://hc.apache.org/httpcomponents-client-ga/tutorial/html/authentication.html

public class Test {
    public static void main(String[] args) throws ClientProtocolException, IOException {

        DefaultHttpClient httpClient;
        URL url = new URL("https://9.5.127.34:443");
        httpClient = getSSLHttpClient(url);
        CredentialsProvider credsProvider = new BasicCredentialsProvider();
        credsProvider.setCredentials(
                new AuthScope("https://9.5.127.34", AuthScope.ANY_PORT),
                new UsernamePasswordCredentials("root", "passw0rd"));


         httpClient.setCredentialsProvider(credsProvider);


        HttpGet httpget = new HttpGet("https://9.5.127.34/powervc/openstack/volume/v1/115e4ad38aef463e8f99991baad1f809//volumes/3627400b-cd98-46c7-a7e2-ebce587a0b05/restricted_metadata");
        HttpResponse response = httpClient.execute(httpget);
        BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
        String line = "";
        while ((line = rd.readLine()) != null) {

            System.out.println(line);

            }   
        }
Run Code Online (Sandbox Code Playgroud)

但它给了我错误

Authentication required
Run Code Online (Sandbox Code Playgroud)

请告诉我我做错了什么.Thanx提前

java apache-commons-httpclient

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

Java Swing GUI控件停止运行,并在后端执行操作

在此输入图像描述

现在,当我单击导入按钮时,将在后端执行操作.为此,GUI停止控制,我不能按任何按钮,但我希​​望取消按钮可用于按下,以便用户可以取消正在进行的操作.我需要一些关于如何做的想法.

JButton importButton = new JButton("Import");
importButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {


    for(ResourceListObject currentImage : imagesToBeImported){

        String ImOid = String.valueOf(currentImage.getOID());


            String image_content = restEngine.getimageContent(ImOid);

            String str[]=new String[3];

            str[0] = "aix";
            str[1] = image_content;
            str[2] = selectedRepository.concat("_").concat(currentImage.getName());

            PowerVC_Image_Deployer imgDeployer= new PowerVC_Image_Deployer(str);



             }

        }
Run Code Online (Sandbox Code Playgroud)

java user-interface swing

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

在javascript中比较日期时间,格式为YYYY-MM-DD HH:MM:SS

我必须在javascript中比较两个日期时间.我有的日期是形式

YYYY-MM-DD HH:MM:SS. 
Run Code Online (Sandbox Code Playgroud)

我正在使用以下代码

var date1 = new Date("2015-08-20 09:38:20");  
var date2 = new Date("2015-08-20 08:00:00");
Run Code Online (Sandbox Code Playgroud)

这里的问题是,当我用"/"代替" - "时,我得到了预期的结果.但是当我采用这种格式时

date1 > date
Run Code Online (Sandbox Code Playgroud)

它返回false

使用momentJs对我来说不是一个选项,而且我从soemewhere获取日期所以必须保留格式.如何在javascript中比较上述给定格式的日期

javascript datetime date

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

Elixir:使用 Dynamic Supervisor 启动孩子的正确方法

我正在尝试创建一个动态主管来启动子进程。我使用三个模块来做到这一点,一个是主模块,第二个是动态主管,第三个是 genserver。我没有收到任何错误,但我看不到任何正在运行的子进程。

这是我的代码。第一个是具有主要方法的模块

defmodule Simulator do
    def main(args) do
        {:ok, super_pid} = PersonManager.start_link(args)
        num_of_persons = 1
        start_persons(num_of_persons)
        IO.inspect PersonManager.count_children, label: "The Persons started in main method are"
    end

    def start_persons(num_of_persons) when num_of_persons >=1 do
        PersonManager.add_node(private_key, public_key, 0)
        start_persons(num_of_persons-1)    
    end
    # num_of_persons == 0 case handled
end   
Run Code Online (Sandbox Code Playgroud)

以下是动态Supervisor

defmodule PersonManager do
  use DynamicSupervisor

  def start_link(args) do
    DynamicSupervisor.start_link(__MODULE__, :ok, name: __MODULE__)
  end

  def add_node(private_key, public_key, num_of_coins) do
    # The code flow does come here, used inspect to check
    child_spec = {Person, {private_key, …
Run Code Online (Sandbox Code Playgroud)

elixir gen-server erlang-supervisor

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

从ArrayList中删除不起作用

for(JCheckBox currentCheckBox : imagesToBeImportedCheckBox){ 
    if(currentCheckBox.isSelected()){
                    System.out.println("The text Box selected for removing are"+currentCheckBox.getText());
                }

             }
            for(JCheckBox currentCheckBox : imagesToBeImportedCheckBox){

                if(currentCheckBox.isSelected()){
                    System.out.println("I am entering in the loop where this image has to be removed "+currentCheckBox.getText());
                    imagesToBeImported.remove(currentCheckBox.getText());

                }

             }
            for(ResourceListObject currentImage : imagesToBeImported){

                System.out.println("After removing the images left are "+currentImage.getName());

             }
Run Code Online (Sandbox Code Playgroud)

这是输出

选择删除的文本框是aix71b

选择要删除的文本框是迁移图像

我进入循环,这个图像必须删除aix71b

我进入循环,必须删除此图像迁移图像

删除后剩下的图像是aix71b

删除图像后,左侧是迁移图像

java arraylist

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

当前显示为未定义golang的方法

我正在尝试从其他目录调用方法,但收到一条错误消息,指出该方法不存在。我有第一个字母大写的方法。

我有以下目录结构

[laptop@laptop src]$ tree
.
??? hello
?   ??? hello.go
??? remote_method
?   ??? remoteMethod.go
Run Code Online (Sandbox Code Playgroud)

我的主要人员在hello.go中,并尝试从remote_method包中调用函数

package main
import 
 (
        "remote_method"
 )

func main() {
     mm := remote_method.NewObject()
     mm.MethodCall()
}
Run Code Online (Sandbox Code Playgroud)

remoteMethod.go具有以下内容

package remote_method

import (
.....
)

type DeclaredType struct {
        randomMap (map[string][](chan int))
}

func NewObject() DeclaredType {
        var randomMap (map[string][](chan int))
        m := DeclaredType{randomMap}
        return m
}

func MethodCall(m DeclaredType, param1 string, param2 string, param3 string, param4 string) {
     // Code to be run
}
Run Code Online (Sandbox Code Playgroud)

我得到错误

mm.MethodCall …
Run Code Online (Sandbox Code Playgroud)

go

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