2017-11-09 1 views
0

현재 PowerBi 커넥터를 개발 중입니다. 나는 회사의 REST-webservice에서 데이터를 얻는다. Tt의 페이지 매김에 대해. 문제는 pageSize가 100이고 데이터베이스에 101 개의 레코드가있는 경우 (첫 번째 호출은 100, 두 번째 레코드는 1 레코드), 호출 원인을 막을 수 없다는 것을 나타냅니다. List.Count는 비어있는 부분에 0이 아닌 값을줍니다. 명부.전원 쿼리 빈 목록이 비어있는 것으로 인식되지 않습니다.

예 데이터 :

{"records":[{"firstname":"...","lastname":"..",}]} 

코드 : 레코드가있는 경우

json = Json.Document(Web.Contents(url, [ 
    Content = Text.ToBinary(body)])), 

    records = Table.FromRecords({json}), 

    recordsExpaned = Table.ExpandTableColumn(records, "records", {"firstname", "lastname"}), 
    recordsTable = Table.ToList(recordsExpaned), 
    result = 
     if(List.Count(recordsTable) < 1) then 
      Data.Contacts(json) meta [NextPage = null] 
     else 
      SData.Contacts(json) meta [NextPage = page + 1] 

내가의 List.Count (recordsTable)가 0 또는 null의 기대

{"records":[]} 

그러나 이것은 사실이 아닙니다.

{"records":[]} 
{"records":[{"firstname":"...","lastname":"..",}]} 

은 동일한 카운트 값을 제공합니다.

이것은 나를 미치게합니다. 내가이

if(List.Count(acd) < 2) then 

처럼을 선택하면 목록이

{"records":[]} 

같은 정말 하늘의 경우는 어떻게하면 그때는 바로 먹으 렴 (빈리스트에 중지뿐만 아니라 하나의 인수 목록에서 확인하실 수 있습니다). 이것은 빈 목록이 실제로 비어 있지 않다는 것을 의미합니다.

편집 :이 @MarcelBeug하는 덕분에

json = Json.Document(Web.Contents(url, [ 
Content = Text.ToBinary(body)])), 

data = Table.FromRecords({json}), 

recordsExpaned = Table.ExpandTableColumn(data, "records", {"firstname", "lastname"}), 
recordsTable = Table.ToList(recordsExpaned), 
result = 
    if(List.IsEmpty(json[records]) = true) then 
     Data.Contacts(json) meta [NextPage = null] 
    else 
     Data.Contacts(json) meta [NextPage = page + 1] 

다음 줄은 IsEmpty 함수-기능이 요소를 찾고 있음을 보인다 게임 체인저

if(List.IsEmpty(json[records]) = true) then 

"기록"이었다 노력하고 있습니다 json에서는 "레코드"를 선언하지 않았습니다. 함수가 요소를 파싱하여 검색 중이지만 Power Query M의 전문가가 아닌 것 같습니다.

답변

1

먼저 문자열을 JSON 값으로 구문 분석해야 레코드가 생성됩니다. 그런 다음 해당 레코드의 "레코드"필드에 빈 목록이 들어 있는지 확인할 수 있습니다.

예 (true를 반환) : 작동하는지

let 
    Source = "{""records"":[]}", 
    #"Parsed JSON" = Json.Document(Source), 
    Custom1 = List.IsEmpty(#"Parsed JSON"[records]) 
in 
    Custom1 
+0

! 나는 처럼 json을 구문 분석합니다. json = Json.Document (Web.Contents (URL, [ Content = Text.ToBinary (body)])), 또는 내가 잘못 되었나요? 변경된 경우 if (List.IsEmpty (json [records]) = true) 어떻게 신고되지 않은 변수 "레코드"를 전달할 수 있습니까? json에서 요소 "레코드"를 찾는 IsEmpty 함수처럼 보일 수도 있지만 작동하지 않아야하는 주 Java 개발자로서 작동합니다. D 대단히 감사합니다! – user3769192

관련 문제