使用java sdk构建一个简单的个性洞察android应用程序,我无法像演示中那样获得所需的JSON输出。
public class Analysis extends AppCompatActivity {
private String textAnalysis;
PersonalityInsights service;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_analysis);
Intent intent = getIntent();
textAnalysis = intent.getStringExtra("data");
Log.i("DATA",textAnalysis+" ff");
service = new PersonalityInsights();
service.setUsernameAndPassword(getString(R.string.user_id),getString(R.string.password));
}
@Override
protected void onStart() {
super.onStart();
new Thread(new Runnable() {
@Override
public void run() {
Profile profile = service.getProfile(textAnalysis+"").execute();
Log.i("Analysis",profile.toString());
Trait trait = profile.getTree();
Log.i("Analysis","Categories"+trait.getCategory());
Log.i("Analysis","Name"+trait.getName());
Log.i("Analysis","Children"+trait.getChildren().get(1).getName());
Log.i("Analysis","Percentage"+trait.getPercentage());
}
}).start();
}
}
但是输出与demo不同。它没有五大人格特质,需求,价值和其他东西
"children": [ {
"children": [
{
"category": "personality",
"children": [
{
"category": "personality",
"children": [
{
"category": "personality",
"id": "Adventurousness",
"name": "Adventurousness",
"percentage": 0.6702837479298441,
"sampling_error": 0.0498460567
},
{
"category": "personality",
"id": "Artistic interests",
"name": "Artistic interests",
"percentage": 0.8054407502066927,
"sampling_error": 0.1015761071
},
{
"category": "personality",
"id": "Emotionality",
"name": "Emotionality",
"percentage": 0.46526949977539345,
"sampling_error": 0.046778333500000005
},
{
"category": "personality",
"id": "Imagination",
"name": "Imagination",
"percentage": 0.1636949533378917,
"sampling_error": 0.0624994068
},
{
"category": "personality",
"id": "Intellect",
"name": "Intellect",
"percentage": 0.9963456758072283,
"sampling_error": 0.0546178831
},
{
"category": "personality",
"id": "Liberalism",
"name": "Authority-challenging",
"percentage": 0.7512306650873422,
"sampling_error": 0.0818740146
}
],
"id": "Openness",
"name": "Openness",
"percentage": 0.9927226873432959,
"sampling_error": 0.0584048909
},
{
"category": "personality",
"children": [
{
"category": "personality",
"id": "Achievement striving",
"name": "Achievement striving",
"percentage": 0.7368742460200748,
"sampling_error": 0.0963623238
},
{
"category": "personality",
"id": "Cautiousness",
"name": "Cautiousness",
"percentage": 0.9743850469356967,
"sampling_error": 0.0897570103
},
{
"category": "personality",
"id": "Dutifulness",
"name": "Dutifulness",
"percentage": 0.9146327962074232,
"sampling_error": 0.059146664099999996
},
{
"category": "personality",
"id": "Orderliness",
"name": "Orderliness",
"percentage": 0.42552691130776477,
"sampling_error": 0.0686670938
},
{
"category": "personality",
"id": "Self-discipline",
"name": "Self-discipline",
"percentage": 0.6471345466162,
"sampling_error": 0.0459092878
},
{
"category": "personality",
"id": "Self-efficacy",
"name": "Self-efficacy",
"percentage": 0.5770567155207881,
"sampling_error": 0.0900573954
}
],
"id": "Conscientiousness",
"name": "C
09-18 06:37:28.688 17768-18972/com.jain.rakshit.personalityanalysis I/Analysis: Categoriesnull
09-18 06:37:28.688 17768-18972/com.jain.rakshit.personalityanalysis I/Analysis: Nameroot
09-18 06:37:28.688 17768-18972/com.jain.rakshit.personalityanalysis I/Analysis: ChildrenNeeds
09-18 06:37:28.688 17768-18972/com.jain.rakshit.personalityanalysis I/Analysis: Percentagenull
答案 0 :(得分:0)
API始终返回包含3个模型,Big5,需求和值的配置文件。
在toString()
对象中调用Profile
方法应该打印整个JSON响应。
我认为这里的问题是您不了解JSON输出。看看API Reference,那里描述了JSON输出。
您还可以使用API Explorer测试API并获取实时结果。