0

我得到了这个简单的 json 响应,但我无法轻松访问该值。回复是这样的

{"email":"ted@ted.com"}

那是在执行 json.toString() 之后。现在我正在尝试访问电子邮件的价值,但我不断收到错误。我以为只是

json.getString("email")

这也是在java中。

编辑:这是我得到的错误

07-22 06:45:11.524: E/AndroidRuntime(9977): FATAL EXCEPTION: AsyncTask #2
07-22 06:45:11.524: E/AndroidRuntime(9977): java.lang.RuntimeException: An error occured while executing doInBackground()
07-22 06:45:11.524: E/AndroidRuntime(9977):     at android.os.AsyncTask$3.done(AsyncTask.java:299)
07-22 06:45:11.524: E/AndroidRuntime(9977):     at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
07-22 06:45:11.524: E/AndroidRuntime(9977):     at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
07-22 06:45:11.524: E/AndroidRuntime(9977):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
07-22 06:45:11.524: E/AndroidRuntime(9977):     at java.util.concurrent.FutureTask.run(FutureTask.java:137)
07-22 06:45:11.524: E/AndroidRuntime(9977):     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
07-22 06:45:11.524: E/AndroidRuntime(9977):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
07-22 06:45:11.524: E/AndroidRuntime(9977):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
07-22 06:45:11.524: E/AndroidRuntime(9977):     at java.lang.Thread.run(Thread.java:856)
07-22 06:45:11.524: E/AndroidRuntime(9977): Caused by: android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
07-22 06:45:11.524: E/AndroidRuntime(9977):     at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:4609)
07-22 06:45:11.524: E/AndroidRuntime(9977):     at android.view.ViewRootImpl.invalidateChildInParent(ViewRootImpl.java:867)
07-22 06:45:11.524: E/AndroidRuntime(9977):     at android.view.ViewGroup.invalidateChild(ViewGroup.java:4066)
07-22 06:45:11.524: E/AndroidRuntime(9977):     at android.view.View.invalidate(View.java:10193)
07-22 06:45:11.524: E/AndroidRuntime(9977):     at android.widget.TextView.invalidateRegion(TextView.java:4375)
07-22 06:45:11.524: E/AndroidRuntime(9977):     at android.widget.TextView.invalidateCursor(TextView.java:4318)
07-22 06:45:11.524: E/AndroidRuntime(9977):     at android.widget.TextView.spanChange(TextView.java:7172)
07-22 06:45:11.524: E/AndroidRuntime(9977):     at android.widget.TextView$ChangeWatcher.onSpanAdded(TextView.java:8759)
07-22 06:45:11.524: E/AndroidRuntime(9977):     at android.text.SpannableStringBuilder.sendSpanAdded(SpannableStringBuilder.java:979)
07-22 06:45:11.524: E/AndroidRuntime(9977):     at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:688)
07-22 06:45:11.524: E/AndroidRuntime(9977):     at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:588)
07-22 06:45:11.524: E/AndroidRuntime(9977):     at android.text.Selection.setSelection(Selection.java:76)
07-22 06:45:11.524: E/AndroidRuntime(9977):     at android.text.Selection.setSelection(Selection.java:87)
07-22 06:45:11.524: E/AndroidRuntime(9977):     at android.text.method.ArrowKeyMovementMethod.initialize(ArrowKeyMovementMethod.java:302)
07-22 06:45:11.524: E/AndroidRuntime(9977):     at android.widget.TextView.setText(TextView.java:3535)
07-22 06:45:11.524: E/AndroidRuntime(9977):     at android.widget.TextView.setText(TextView.java:3405)
07-22 06:45:11.524: E/AndroidRuntime(9977):     at android.widget.EditText.setText(EditText.java:80)
07-22 06:45:11.524: E/AndroidRuntime(9977):     at android.widget.TextView.setText(TextView.java:3380)
07-22 06:45:11.524: E/AndroidRuntime(9977):     at com.reflap.reflap.EditProfile$fillfields.doInBackground(EditProfile.java:61)
07-22 06:45:11.524: E/AndroidRuntime(9977):     at com.reflap.reflap.EditProfile$fillfields.doInBackground(EditProfile.java:1)
07-22 06:45:11.524: E/AndroidRuntime(9977):     at android.os.AsyncTask$2.call(AsyncTask.java:287)
07-22 06:45:11.524: E/AndroidRuntime(9977):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
07-22 06:45:11.524: E/AndroidRuntime(9977):     ... 5 more

我正在后台进程中执行此操作。

4

1 回答 1

2

我相信您的堆栈跟踪不是由 JSON 数据的解析引起的,而是因为您在方法AsyncTask中引用了 UI(一些TextViewdoInBackground

您通常会引用您的意见onPostExecute,可能通过WeakReferences.

于 2013-07-22T10:51:27.993 回答