如何将以下C代码转换为JNI C代码:
UT_STATIC JsonResult PublishGps(GPS_VARS * vars)
{
JsonResult result;
JsonBuilderData jsonBuilderData;
#define METERS_SECOND_TO_MPH 2.236936
memset(m_GpsJsonBuffer, 0,GPS_JSON_BUFFER_SIZE );
InitJsonBuilder(&jsonBuilderData, m_GpsJsonCache, GPS_JSON_CACHE_SIZE, m_GpsJsonBuffer, GPS_JSON_BUFFER_SIZE);
uint32_t myTest = (uint32_t) vars->rawGps.time;
(void) PutJsonDateTime(myTest, FIELD(AMERIGO_TIMESTAMP_NAME));
(void) PutJsonLong((int32_t) myTest, FIELD(AMERIGO_EPOCH_NAME));
(void) PutJsonString(vars->dsn, FIELD(AMERIGO_DSN_NAME));
if (vars->rawGps.mode == 3)
{ (void) PutJsonString("good", FIELD(AMERIGO_QUALITY_NAME)); }
else
{
{ (void) PutJsonString("none", FIELD(AMERIGO_QUALITY_NAME)); }
}
(void) PutJsonDouble(AMERIGO_PREC,(float64_t) vars->rawGps.lat, FIELD(AMERIGO_LAT_NAME));
(void) PutJsonDouble(AMERIGO_PREC, (float64_t) vars->rawGps.lon, FIELD(AMERIGO_LON_NAME));
float64_t speedMph = (float64_t) vars->rawGps.speed * METERS_SECOND_TO_MPH;
(void) PutJsonDouble(AMERIGO_PREC_SPEED, (float64_t) speedMph,FIELD(AMERIGO_SPEED_NAME));
int32_t heading = (int32_t)vars->rawGps.track;
(void) PutJsonLong(heading, FIELD(AMERIGO_HEADING_NAME));
result = BuildJson(vars->gpsPayLoadBuffer, GPS_PAYLOAD_STRING_SIZE);
vars->payloadSize = strlen(vars->gpsPayLoadBuffer);
if (result != jsonSuccess) { ERROR("%s json error %s", __FUNCTION__, JsonStrerr(result)); }
//reschedule
vars->nextDrop = vars->dropPeriod + vars->currentTick;
return result;
}
我想知道将JsonResult
数据类型转换为什么?它应该是jstring
,jint
等.JNI代码用于JSON字符串或JSON对象的是什么?任何帮助将不胜感激。
答案 0 :(得分:1)
看看这里:
https://github.com/mkowsiak/jnicookbook/tree/master/recipeNo021
你有一个示例代码,你有JNI包装器调用同一共享库中的另一个函数。
您想要做的是:
您可以在此处查看有关在Java和JNI之间来回传递String的示例:
http://jnicookbook.owsiak.org/recipe-No-009/ http://jnicookbook.owsiak.org/recipe-No-010/
我希望这会有所帮助。和JNI一起玩。