[Question]Android send json data to DotNet WCF Api

eric010101

Member
Licensed User
Longtime User
I send json data to DotNet WCF Api,
but it has some Error : Bad Request 400

code:
JSON="[{"authkey":"kesy","id":"00AABBCC"}]"
req.InitializePost2(url,JSON.GetBytes("UTF8"))
req.SetContentType("application/json")
hc.Execute(req,1)

when i asked the WCF Api company
they sad i should Replace " to \" in the JSON format
like it:[{\"authkey\":\"kesy\",\"id\":\"00AABBCC\"}]

but when i do it,it`s not work
always get the same Error: Bad Request 400

what can i do?:sign0085:
 

vincentehsu

Member
Licensed User
Longtime User
dear eric:
did u find answer for this issue? could u please share the projct with me? there is no other actually sample code for wcf via json
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
B4X:
Sub CallWebservice
  Dim URL As String  = "http://api.geonames.org/citiesJSON"
  Log(URL)
  
    Dim job As HttpJob
    job.Initialize("test",Me)
    '?formatted=true&north=44.1&south=-9.9&east=-22.4&west=55.2
    job.download2(URL, Array As String( _
        "username", "putyourusernamehere", _
        "north", 44.1, _
        "south", 9.9, _
        "east", 22.4, _
        "west", 55.2, _
        "type", "json", _
        "lang", "de", _
        "style", "full", _
        "maxRows", 10, _
        "formatted", True _
    ))
    job.GetRequest.Timeout = 6000000
End Sub

Sub JobDone (Job As HttpJob)
   Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
   If Job.Success = True Then
      Select Job.JobName
         Case "test"
            'print the result to the logs
            Log(Job.GetString)
                        Dim parser As JSONParser
                        parser.Initialize(Job.GetString)
                        Dim root As Map = parser.NextObject
                        Dim geonames As List = root.Get("geonames")
                        For Each colgeonames As Map In geonames
                            Dim fcodeName As String = colgeonames.Get("fcodeName")
                            Dim toponymName As String = colgeonames.Get("toponymName")
                            Dim countrycode As String = colgeonames.Get("countrycode")
                            Log("countrycode="&countrycode)
                            Dim fcl As String = colgeonames.Get("fcl")
                            Log("fcl="&fcl)
                            Dim fclName As String = colgeonames.Get("fclName")
                            Log("fclname="&fclName)
                            Dim name As String = colgeonames.Get("name")
                            Log("name="&name)
                            Dim wikipedia As String = colgeonames.Get("wikipedia")
                            Dim lng As Double = colgeonames.Get("lng")
                            Dim fcode As String = colgeonames.Get("fcode")
                            Dim geonameId As Int = colgeonames.Get("geonameId")
                            Dim lat As Double = colgeonames.Get("lat")
                            Dim population As Int = colgeonames.Get("population")
                            Log("population="&population)
                            Log("======================================================")
                        Next
            End Select
   Else
      Log("Error: " & Job.ErrorMessage)
      ToastMessageShow("Error: " & Job.ErrorMessage, True)
   End If
   Job.Release
End Sub

** Activity (main) Resume **
** Service (httputils2service) Create **
** Service (httputils2service) Start **
JobName = test, Success = true
{"geonames": [


{
"fcodeName": "capital of a political entity",
"toponymName": "Mexico City",
"countrycode": "MX",
"fcl": "P",
"fclName": "city, village,...",
"name": "Mexiko-Stadt",
"wikipedia": "en.wikipedia.org/wiki/Mexico_City",
"lng": -99.12766456604,
"fcode": "PPLC",
"geonameId": 3530597,
"lat": 19.428472427036,
"population": 12294193
},
{
"fcodeName": "capital of a political entity",
"toponymName": "Beijing",
"countrycode": "CN",
"fcl": "P",
"fclName": "city, village,...",
"name": "Peking",
"wikipedia": "en.wikipedia.org/wiki/Beijing",
"lng": 116.397228240967,
"fcode": "PPLC",
"geonameId": 1816670,
"lat": 39.9074977414405,
"population": 11716620
},
{
"fcodeName": "capital of a political entity",
"toponymName": "Manila",
"countrycode": "PH",
"fcl": "P",
"fclName": "city, village,...",
"name": "Manila",
"wikipedia": "en.wikipedia.org/wiki/Manila",
"lng": 120.9822,
"fcode": "PPLC",
"geonameId": 1701668,
"lat": 14.6042,
"population": 10444527
},
{
"fcodeName": "capital of a political entity",
"toponymName": "Dhaka",
"countrycode": "BD",
"fcl": "P",
"fclName": "city, village,...",
"name": "Dhaka",
"wikipedia": "en.wikipedia.org/wiki/Dhaka",
"lng": 90.40743827819824,
"fcode": "PPLC",
"geonameId": 1185241,
"lat": 23.710395616597037,
"population": 10356500
},
{
"fcodeName": "capital of a political entity",
"toponymName": "Seoul",
"countrycode": "KR",
"fcl": "P",
"fclName": "city, village,...",
"name": "Seoul",
"wikipedia": "en.wikipedia.org/wiki/Seoul",
"lng": 126.9784,
"fcode": "PPLC",
"geonameId": 1835848,
"lat": 37.566,
"population": 10349312
},
{
"fcodeName": "capital of a political entity",
"toponymName": "Tokyo",
"countrycode": "JP",
"fcl": "P",
"fclName": "city, village,...",
"name": "Tokio",
"wikipedia": "de.wikipedia.org/wiki/Tokyo",
"lng": 139.69171,
"fcode": "PPLC",
"geonameId": 1850147,
"lat": 35.6895,
"population": 8336599
},
{
"fcodeName": "capital of a political entity",
"toponymName": "Taipei",
"countrycode": "TW",
"fcl": "P",
"fclName": "city, village,...",
"name": "Taipeh",
"wikipedia": "de.wikipedia.org/wiki/Taipei",
"lng": 121.531846,
"fcode": "PPLC",
"geonameId": 1668341,
"lat": 25.047763,
"population": 7871900
},
{
"fcodeName": "capital of a political entity",
"toponymName": "Hong Kong",
"countrycode": "HK",
"fcl": "P",
"fclName": "city, village,...",
"name": "Hong Kong",
"wikipedia": "en.wikipedia.org/wiki/Hong_Kong",
"lng": 114.157691001892,
"fcode": "PPLC",
"geonameId": 1819729,
"lat": 22.2855225817732,
"population": 7012738
},
{
"fcodeName": "capital of a political entity",
"toponymName": "Bangkok",
"countrycode": "TH",
"fcl": "P",
"fclName": "city, village,...",
"name": "Bangkok",
"wikipedia": "en.wikipedia.org/wiki/Bangkok",
"lng": 100.501444,
"fcode": "PPLC",
"geonameId": 1609350,
"lat": 13.753979,
"population": 5104476
},
{
"fcodeName": "capital of a political entity",
"toponymName": "Madrid",
"countrycode": "ES",
"fcl": "P",
"fclName": "city, village,...",
"name": "Madrid",
"wikipedia": "en.wikipedia.org/wiki/Madrid",
"lng": -3.70256423950195,
"fcode": "PPLC",
"geonameId": 3117735,
"lat": 40.4165020941502,
"population": 3255944
}
]}
countrycode=MX
fcl=P
fclname=city, village,...
name=Mexiko-Stadt
population=1.2294193E7
======================================================
countrycode=CN
fcl=P
fclname=city, village,...
name=Peking
population=1.171662E7
======================================================
countrycode=PH
fcl=P
fclname=city, village,...
name=Manila
population=1.0444527E7
======================================================
countrycode=BD
fcl=P
fclname=city, village,...
name=Dhaka
population=1.03565E7
======================================================
countrycode=KR
fcl=P
fclname=city, village,...
name=Seoul
population=1.0349312E7
======================================================
countrycode=JP
fcl=P
fclname=city, village,...
name=Tokio
population=8336599
======================================================
countrycode=TW
fcl=P
fclname=city, village,...
name=Taipeh
population=7871900
======================================================
countrycode=HK
fcl=P
fclname=city, village,...
name=Hong Kong


population=7012738
======================================================
countrycode=TH
fcl=P
fclname=city, village,...
name=Bangkok
population=5104476
======================================================
countrycode=ES
fcl=P
fclname=city, village,...
name=Madrid
population=3255944
======================================================
** Activity (main) Pause, UserClosed = true **

{"geonames": [


{
"fcodeName": "capital of a political entity",
"toponymName": "Mexico City",
"countrycode": "MX",
"fcl": "P",
"fclName": "city, village,...",
"name": "Mexiko-Stadt",
"wikipedia": "en.wikipedia.org/wiki/Mexico_City",
"lng": -99.12766456604,
"fcode": "PPLC",
"geonameId": 3530597,
"lat": 19.428472427036,
"population": 12294193
},
{
"fcodeName": "capital of a political entity",
"toponymName": "Beijing",
"countrycode": "CN",
"fcl": "P",
"fclName": "city, village,...",
"name": "Peking",
"wikipedia": "en.wikipedia.org/wiki/Beijing",
"lng": 116.397228240967,
"fcode": "PPLC",
"geonameId": 1816670,
"lat": 39.9074977414405,
"population": 11716620
},
{
"fcodeName": "capital of a political entity",
"toponymName": "Manila",
"countrycode": "PH",
"fcl": "P",
"fclName": "city, village,...",
"name": "Manila",
"wikipedia": "en.wikipedia.org/wiki/Manila",
"lng": 120.9822,
"fcode": "PPLC",
"geonameId": 1701668,
"lat": 14.6042,
"population": 10444527
},
{
"fcodeName": "capital of a political entity",
"toponymName": "Dhaka",
"countrycode": "BD",
"fcl": "P",
"fclName": "city, village,...",
"name": "Dhaka",
"wikipedia": "en.wikipedia.org/wiki/Dhaka",
"lng": 90.40743827819824,
"fcode": "PPLC",
"geonameId": 1185241,
"lat": 23.710395616597037,
"population": 10356500
},
{
"fcodeName": "capital of a political entity",
"toponymName": "Seoul",
"countrycode": "KR",
"fcl": "P",
"fclName": "city, village,...",
"name": "Seoul",
"wikipedia": "en.wikipedia.org/wiki/Seoul",
"lng": 126.9784,
"fcode": "PPLC",
"geonameId": 1835848,
"lat": 37.566,
"population": 10349312
},
{
"fcodeName": "capital of a political entity",
"toponymName": "Tokyo",
"countrycode": "JP",
"fcl": "P",
"fclName": "city, village,...",
"name": "Tokio",
"wikipedia": "de.wikipedia.org/wiki/Tokyo",
"lng": 139.69171,
"fcode": "PPLC",
"geonameId": 1850147,
"lat": 35.6895,
"population": 8336599
},
{
"fcodeName": "capital of a political entity",
"toponymName": "Taipei",
"countrycode": "TW",
"fcl": "P",
"fclName": "city, village,...",
"name": "Taipeh",
"wikipedia": "de.wikipedia.org/wiki/Taipei",
"lng": 121.531846,
"fcode": "PPLC",
"geonameId": 1668341,
"lat": 25.047763,
"population": 7871900
},
{
"fcodeName": "capital of a political entity",
"toponymName": "Hong Kong",
"countrycode": "HK",
"fcl": "P",
"fclName": "city, village,...",
"name": "Hong Kong",
"wikipedia": "en.wikipedia.org/wiki/Hong_Kong",
"lng": 114.157691001892,
"fcode": "PPLC",
"geonameId": 1819729,
"lat": 22.2855225817732,
"population": 7012738
},
{
"fcodeName": "capital of a political entity",
"toponymName": "Bangkok",
"countrycode": "TH",
"fcl": "P",
"fclName": "city, village,...",
"name": "Bangkok",
"wikipedia": "en.wikipedia.org/wiki/Bangkok",
"lng": 100.501444,
"fcode": "PPLC",
"geonameId": 1609350,
"lat": 13.753979,
"population": 5104476
},
{
"fcodeName": "capital of a political entity",
"toponymName": "Madrid",
"countrycode": "ES",
"fcl": "P",
"fclName": "city, village,...",
"name": "Madrid",
"wikipedia": "en.wikipedia.org/wiki/Madrid",
"lng": -3.70256423950195,
"fcode": "PPLC",
"geonameId": 3117735,
"lat": 40.4165020941502,
"population": 3255944
}
]}
 

Attachments

  • webservicesjson.zip
    6.9 KB · Views: 216
Upvote 0
Top