将json文件解析为javax.json库

时间:2015-09-01 14:07:39

标签: java json

尝试使用FileInputStream json = new FileInputStream("testJSON.json"); JsonParser parser = Json.createParser(json); 来阅读一些json数据。目前我没有问题以这种方式读取文件(跳过异常处理):

testJSON.json

当我有一个单独的json文件时,这个工作正常,在这种情况下它是json。现在我想要做的只是解析json字符串,而不是[{"Gross Weight":"12","Tare Weight":"3","Price Per Pound":"2"},{"Gross Weight":"123","Tare Weight":"32","Price Per Pound":"23"}] 文件。例如,我有一个json字符串,如下所示:

JsonParser

是否可以将此func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) { let deviceTokenStr = HDDataLayer.convertDeviceTokenToStr(deviceToken) HDDataLayer.postNotificationServiceResponseByUrlString("pushnotifications/notifications/register", andParams: tempDict, andDictCompletion: { (response: AnyObject!, error: NSError!) -> Void in NSLog("Device Register successfully") }) } 数据解析为 package com.example.notifi; import java.util.Calendar; import android.app.Activity; import android.app.AlarmManager; import android.app.PendingIntent; import android.content.Intent; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.HOUR_OF_DAY, 18); calendar.set(Calendar.MINUTE, 30); calendar.set(Calendar.SECOND, 0); Intent intent1 = new Intent(MainActivity.this, Notificationmassage.class); PendingIntent pendingIntent = PendingIntent.getBroadcast(MainActivity.this, 0,intent1, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager am = (AlarmManager) MainActivity.this.getSystemService(MainActivity.this.ALARM_SERVICE); am.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent); } } ?或者任何其他Java库可以处理此请求?

1 个答案:

答案 0 :(得分:0)

java.io.StringReader in = new java.io.StringReader(theString);
JsonParser parser = Json.createParser(in);

请不时研究您正在使用的图书馆的Javadoc。