jsonschema2pojo not generating class - android

With the json response I am not getting the jsonschema2pojo class.
I am getting error like this "There's a problem: Unexpected character ('r' (code 114)): was expecting double-quote to start field name (line 2, column 2)".
I am newer in retrofit.Please help me.Thanks in advance.

Finally I got the solution that you need to put "" to all of your response parameter.

Related

Unhandled Exception: type 'String' is not a subtype of type 'int' of 'index' error in dart

I have tried to decode a json file which is coming back from server after my request, but when i want to decode the json it show an error
here is my decode codes:
var loginJson = jsonDecode(utf8.decode(response.bodyBytes));
var model = idResponseModel(
loginJson['id'],
loginJson["fname"],
loginJson["lname"],
loginJson["nationalCode"],
loginJson["gender"],
loginJson["bornDate"],
loginJson["phoneNumber"],
loginJson["cardNumber"],
loginJson["enabled"]);
print(model.id);
and console says it happened in loginJson['id']
the id from server is some thing like this :
"id": "5de0a41e-9a6f-4b55-9567-024cd0fdbfc5"
slightly surprised by the direct use of [bodyBytes] try using the Response getter → body
String get body => _encodingForHeaders(headers).decode(bodyBytes);
in your case it should look like this:
var loginJson = jsonDecode(response.body);
var model = idResponseModel(
loginJson['id'],
loginJson["fname"],
loginJson["lname"],
loginJson["nationalCode"],
loginJson["gender"],
loginJson["bornDate"],
loginJson["phoneNumber"],
loginJson["cardNumber"],
loginJson["enabled"]);
print(model.id);
I have no way to check it now but if it works let me know
This error means that loginJson.[] expects an int, not a String. So it's possible that loginJson is actually a List, and not a Map like you expect it to be. You can check by printing loginJson.runtimeType.
Unless you'd post the whole JSON, this question is insufficient and not reproducible... because you might believe you have the response already, while trying to get data from the wrong one node (id is a string index, but it encounters an unexpected numeric index). That's exactly why your sample data and the error message do not provide the least meaning in combination.

retrofit error when fetching pretty print json from php

I write a simple program for fetching some json data and I hit by this error
Expected BEGIN_ARRAY but was STRING at line 1 column 1 path $
I searched in stackoverflow and I didn't get the answer
but I figured out this error is because of "JSON_PRETTY_PRINT" code in json encode or the pre tag maybe
.
I changed this :
echo "<pre>".json_encode($row,JSON_PRETTY_PRINT)."</pre>";
to this :
echo json_encode($row);
and it worked. But the printed json is really messy and ugly. Do you have any solution for this problem ?
Use retrofit library and probably you are sending an array but on parsing you parse it as an Object not an array, thats problem

Parse xml Data from FormBuilder

I get the following response for FormBuilder. I want parse it.
How to parse it??
<LoactionApi><Status>OK</Status><ReportURL/><
Locations>
<Location><name>jack</name><number>357-151-04-00</number><Address>Ahmedabad</Address><City>Ahmedabad</City><State>Gujarat</State><ZIP>380007</ZIP><ZIP4>6518</ZIP4><UnitType/><UnitNumber/>
<MatchStatus>No Exact Match</MatchStatus>
<StatusCode>NM</StatusCode>
</LoactionApi>
Thanks
Please check your XML response that you have shown over here. It is not at all valid !!!
For checking that your xml is valid. Validate it over here
http://www.xmlvalidation.com/
Show me the correct xml. I will help you

Mysql Connection, how to request data correctly?

I'm trying to follow this tutorial in order to connect to an external database with android:
http://www.helloandroid.com/tutorials/connecting-mysql-database
However, I seem to receive two different errors when viewing the php / mysql connection code directly
and through logcat.
If I look at it through a browser, it comes up with the orange php error saying:
Undefined index: year
Found on line 6 with .$_REQUEST['year'].
If i debug the app and look at the logcat output, it seems to give a half error:
E/log_tag ( 403): Error parsing data org.json.JSONException: A JSONArray text m
ust start with '[' at character 6 of
On the php page, below the error, Json prints off the tables correctly, and echoing mysql errors are fine.
Can anyone help with the implementation of this function $_REQUEST please? (If that is the problem.)
Your output comes from the http request must be a well formed json string.
Obviously a PHP error like an Undefined index can break the json string and makes it unparsable by java.
You need to rid off the notice, for istance:
<?php
if (isset($_REQUEST['year']) && $_REQUEST['year'] == 'foo'){
//Do query and output back the json array
}
?>
BTW $_REQUEST is not a function. Is a superglobal associative array where all request variables (GET/POST/COOKIE) are stored.

numberFormatException

Is this sequence correct in android? I am tring to get EditText value and convert it into integer.
startTime_hour_int=Integer.parseInt(startTime_hour_edittext.getEditableText().toString());
Because my logcat throws the below error.
05-12 10:26:35.536: ERROR/AndroidRuntime(293): java.lang.NumberFormatException: unable to parse '' as integer
Can anyone tell me, how to solve this?
#Andro_Selva
If textbox startTime_hour_edittext is blank then Integer.parseInt is trying to parse "" into integer thats why you are getting NumberFormatException
so before use of startTime_hour_int=Integer.parseInt(startTime_hour_edittext.getEditableText().toString());
check condition
if(!startTime_hour_edittext.getText().toString().equalsIgnoreCase("")) {
startTime_hour_int=Integer.parseInt(startTime_hour_edittext.getEditableText().toString());
}
Do you call this code from some kind of listener on the EditBox? This can happen when you delete all content from the box. Just check that the text is not empty before parsing it to int.

Categories

Resources