尝试整理出IBM bluemix个性洞察力检索到的JSON文件,以便可以显示类似的结果。

Personality: Adventurousness = 0.6317251869427992%;
Personality: Artistic interests = 0.9994303217024612%;
etc.


尝试使用Gson从JSON文件传递变量,但不起作用。有没有更好的方法可以做到这一点,还是Gson仍然是解析JSON文件中元素的好方法。我正在使用的JSON文件也在下面创建:

    {
  "id": "*UNKNOWN*",
  "processed_lang": "en",
  "source": "*UNKNOWN*",
  "tree": {
    "children": [
      {
        "children": [
          {
            "category": "personality",
            "children": [
              {
                "category": "personality",
                "children": [
                  {
                    "category": "personality",
                    "id": "Adventurousness",
                    "name": "Adventurousness",
                    "percentage": 0.6317251869427992,
                    "sampling_error": 0.0550028572
                  },
                  {
                    "category": "personality",
                    "id": "Artistic interests",
                    "name": "Artistic interests",
                    "percentage": 0.9994303217024612,
                    "sampling_error": 0.1112535152
                  },
                  {
                    "category": "personality",
                    "id": "Emotionality",
                    "name": "Emotionality",
                    "percentage": 0.9110319825845377,
                    "sampling_error": 0.0517194892
                  },
                  {
                    "category": "personality",
                    "id": "Imagination",
                    "name": "Imagination",
                    "percentage": 0.9563652127187121,
                    "sampling_error": 0.0692827052
                  },
                  {
                    "category": "personality",
                    "id": "Intellect",
                    "name": "Intellect",
                    "percentage": 0.9993135468190391,
                    "sampling_error": 0.0609848988
                  },
                  {
                    "category": "personality",
                    "id": "Liberalism",
                    "name": "Authority-challenging",
                    "percentage": 0.9992476810581103,
                    "sampling_error": 0.0889871444
                  }
                ],
                "id": "Openness",
                "name": "Openness",
                "percentage": 0.9846019609615686,
                "sampling_error": 0.0659049028
              },
              {
                "category": "personality",
                "children": [
                  {
                    "category": "personality",
                    "id": "Achievement striving",
                    "name": "Achievement striving",
                    "percentage": 0.48216415575634164,
                    "sampling_error": 0.1055280664
                  },
                  {
                    "category": "personality",
                    "id": "Cautiousness",
                    "name": "Cautiousness",
                    "percentage": 0.9645239970907649,
                    "sampling_error": 0.0975392952
                  },
                  {
                    "category": "personality",
                    "id": "Dutifulness",
                    "name": "Dutifulness",
                    "percentage": 0.48295582786617886,
                    "sampling_error": 0.067074676
                  },
                  {
                    "category": "personality",
                    "id": "Orderliness",
                    "name": "Orderliness",
                    "percentage": 0.8923116642953849,
                    "sampling_error": 0.0750867144
                  },
                  {
                    "category": "personality",
                    "id": "Self-discipline",
                    "name": "Self-discipline",
                    "percentage": 0.12761071487631187,
                    "sampling_error": 0.0507461328
                  },
                  {
                    "category": "personality",
                    "id": "Self-efficacy",
                    "name": "Self-efficacy",
                    "percentage": 0.47236420942319157,
                    "sampling_error": 0.0984568308
                  }
                ],
                "id": "Conscientiousness",
                "name": "Conscientiousness",
                "percentage": 0.20312039774513813,
                "sampling_error": 0.0823480716
              },
              {
                "category": "personality",
                "children": [
                  {
                    "category": "personality",
                    "id": "Activity level",
                    "name": "Activity level",
                    "percentage": 0.3721671469083689,
                    "sampling_error": 0.0837163552
                  },
                  {
                    "category": "personality",
                    "id": "Assertiveness",
                    "name": "Assertiveness",
                    "percentage": 0.3608814928456784,
                    "sampling_error": 0.0891259996
                  },
                  {
                    "category": "personality",
                    "id": "Cheerfulness",
                    "name": "Cheerfulness",
                    "percentage": 0.168558437901277,
                    "sampling_error": 0.1118533964
                  },
                  {
                    "category": "personality",
                    "id": "Excitement-seeking",
                    "name": "Excitement-seeking",
                    "percentage": 0.526708697277564,
                    "sampling_error": 0.0853730664
                  },
                  {
                    "category": "personality",
                    "id": "Friendliness",
                    "name": "Outgoing",
                    "percentage": 0.27834657828325515,
                    "sampling_error": 0.0804874488
                  },
                  {
                    "category": "personality",
                    "id": "Gregariousness",
                    "name": "Gregariousness",
                    "percentage": 0.15285819617130203,
                    "sampling_error": 0.0618727368
                  }
                ],
                "id": "Extraversion",
                "name": "Extraversion",
                "percentage": 0.3684311825466099,
                "sampling_error": 0.0617198188
              },
              {
                "category": "personality",
                "children": [
                  {
                    "category": "personality",
                    "id": "Altruism",
                    "name": "Altruism",
                    "percentage": 0.5198409884448938,
                    "sampling_error": 0.0760231772
                  },
                  {
                    "category": "personality",
                    "id": "Cooperation",
                    "name": "Cooperation",
                    "percentage": 0.8204615138656874,
                    "sampling_error": 0.0845446968
                  },
                  {
                    "category": "personality",
                    "id": "Modesty",
                    "name": "Modesty",
                    "percentage": 0.3028236905698857,
                    "sampling_error": 0.0608841808
                  },
                  {
                    "category": "personality",
                    "id": "Morality",
                    "name": "Uncompromising",
                    "percentage": 0.3683263428886422,
                    "sampling_error": 0.067562902
                  },
                  {
                    "category": "personality",
                    "id": "Sympathy",
                    "name": "Sympathy",
                    "percentage": 0.9458613463480976,
                    "sampling_error": 0.1038568852
                  },
                  {
                    "category": "personality",
                    "id": "Trust",
                    "name": "Trust",
                    "percentage": 0.8915942559871681,
                    "sampling_error": 0.0624363272
                  }
                ],
                "id": "Agreeableness",
                "name": "Agreeableness",
                "percentage": 0.07292135773434255,
                "sampling_error": 0.10250565
              },
              {
                "category": "personality",
                "children": [
                  {
                    "category": "personality",
                    "id": "Anger",
                    "name": "Fiery",
                    "percentage": 0.02340275040082851,
                    "sampling_error": 0.0999794916
                  },
                  {
                    "category": "personality",
                    "id": "Anxiety",
                    "name": "Prone to worry",
                    "percentage": 0.39598631299245396,
                    "sampling_error": 0.0596402444
                  },
                  {
                    "category": "personality",
                    "id": "Depression",
                    "name": "Melancholy",
                    "percentage": 0.3929152963217911,
                    "sampling_error": 0.06402023080000001
                  },
                  {
                    "category": "personality",
                    "id": "Immoderation",
                    "name": "Immoderation",
                    "percentage": 0.6895235350576241,
                    "sampling_error": 0.057768048
                  },
                  {
                    "category": "personality",
                    "id": "Self-consciousness",
                    "name": "Self-consciousness",
                    "percentage": 0.5331328944254717,
                    "sampling_error": 0.0617367476
                  },
                  {
                    "category": "personality",
                    "id": "Vulnerability",
                    "name": "Susceptible to stress",
                    "percentage": 0.16507939784505093,
                    "sampling_error": 0.09147593000000001
                  }
                ],
                "id": "Neuroticism",
                "name": "Emotional range",
                "percentage": 0.5734234749195765,
                "sampling_error": 0.097180016
              }
            ],
            "id": "Openness_parent",
            "name": "Openness",
            "percentage": 0.9846019609615686
          }
        ],
        "id": "personality",
        "name": "Big 5"
      },
      {
        "children": [
          {
            "category": "needs",
            "children": [
              {
                "category": "needs",
                "id": "Challenge",
                "name": "Challenge",
                "percentage": 0.2163701166672924,
                "sampling_error": 0.088382552
              },
              {
                "category": "needs",
                "id": "Closeness",
                "name": "Closeness",
                "percentage": 0.31761617269156583,
                "sampling_error": 0.08715462160000001
              },
              {
                "category": "needs",
                "id": "Curiosity",
                "name": "Curiosity",
                "percentage": 0.9247945752958546,
                "sampling_error": 0.1257142204
              },
              {
                "category": "needs",
                "id": "Excitement",
                "name": "Excitement",
                "percentage": 0.29876054433673094,
                "sampling_error": 0.1150890848
              },
              {
                "category": "needs",
                "id": "Harmony",
                "name": "Harmony",
                "percentage": 0.5632884023172972,
                "sampling_error": 0.115445782
              },
              {
                "category": "needs",
                "id": "Ideal",
                "name": "Ideal",
                "percentage": 0.11175906677024067,
                "sampling_error": 0.10459386120000001
              },
              {
                "category": "needs",
                "id": "Liberty",
                "name": "Liberty",
                "percentage": 0.15242136815334956,
                "sampling_error": 0.1516857684
              },
              {
                "category": "needs",
                "id": "Love",
                "name": "Love",
                "percentage": 0.5300501971205276,
                "sampling_error": 0.1061716772
              },
              {
                "category": "needs",
                "id": "Practicality",
                "name": "Practicality",
                "percentage": 0.2652581576775723,
                "sampling_error": 0.0925707984
              },
              {
                "category": "needs",
                "id": "Self-expression",
                "name": "Self-expression",
                "percentage": 0.4226113277009137,
                "sampling_error": 0.0858659712
              },
              {
                "category": "needs",
                "id": "Stability",
                "name": "Stability",
                "percentage": 0.39124496873185977,
                "sampling_error": 0.11233243080000001
              },
              {
                "category": "needs",
                "id": "Structure",
                "name": "Structure",
                "percentage": 0.082319764233448,
                "sampling_error": 0.0845231684
              }
            ],
            "id": "Curiosity_parent",
            "name": "Curiosity",
            "percentage": 0.9247945752958546
          }
        ],
        "id": "needs",
        "name": "Needs"
      },
      {
        "children": [
          {
            "category": "values",
            "children": [
              {
                "category": "values",
                "id": "Conservation",
                "name": "Conservation",
                "percentage": 0.02758870597873586,
                "sampling_error": 0.0718139704
              },
              {
                "category": "values",
                "id": "Openness to change",
                "name": "Openness to change",
                "percentage": 0.7985238196496101,
                "sampling_error": 0.06952367
              },
              {
                "category": "values",
                "id": "Hedonism",
                "name": "Hedonism",
                "percentage": 0.5013608564027453,
                "sampling_error": 0.14348115520000002
              },
              {
                "category": "values",
                "id": "Self-enhancement",
                "name": "Self-enhancement",
                "percentage": 0.14340520219382769,
                "sampling_error": 0.10937856280000001
              },
              {
                "category": "values",
                "id": "Self-transcendence",
                "name": "Self-transcendence",
                "percentage": 0.45891860839197324,
                "sampling_error": 0.08747207800000001
              }
            ],
            "id": "Conservation_parent",
            "name": "Conservation",
            "percentage": 0.02758870597873586
          }
        ],
        "id": "values",
        "name": "Values"
      }
    ],
    "id": "r",
    "name": "root"
  },
  "word_count": 104,
  "word_count_message": "There were 104 words in the input. We need a minimum of 600, preferably 1,200 or more, to compute statistically significant estimates"
}

最佳答案

我建议使用Watson Developer Cloud Java SDK,它会为您完成此映射。它提供了一个包装了Personality Insights结果的Java对象。见https://github.com/watson-developer-cloud/java-sdk/tree/master/personality-insights#usage

09-25 17:50